Qodana 2021.2 Help

Qodana for Python

official project

Qodana Python is based on PyCharm Professional and provides static analysis for Python projects.

Try it now

Analyze a project locally

To start, pull the image from Docker Hub (only necessary to get the latest version):

docker pull jetbrains/qodana-python

For a basic Python project, which only uses stdlib, no preliminary steps are required.

In case a project has external pypi dependencies, use any of the following options:

  • Create virtualenv as a subfolder in your project and exclude it in qodana.yaml to skip analysis of vendor code.

  • Mount a separate virtualenv as cache.

    When you create the virtualenv folder, no actual python binary is copied into it. Instead, a symlink is created to python binary used to create virtualenv. This could lead to incorrect paths when your virtualenv is being read inside the Qodana container, since python location there could be different. To fix this, create virtualenv using the Qodana container's python:

    docker run --rm \ -v <source-directory>/:/data/project/ \ -v <cache-directory>/:/data/cache/ \ --entrypoint=bash \ jetbrains/qodana-python -c ' python3 -m venv /data/cache/venv source /data/cache/venv/bin/activate pip3 install -r /data/project/requirements.txt '

The project dependencies are now stored in <cache-directory>. This folder could be preserved between builds to speed them up.

Start local analysis with cache mounted and with source-directory pointing to the root of your project, and it would automatically look for virtualenv in /data/cache/venv:

docker run --rm -it -p 8080:8080 \ -v <source-directory>/:/data/project/ \ -v <output-directory>/:/data/results/ \ -v <cache-directory>/:/data/cache/ \ jetbrains/qodana-python --show-report

This command will run the analysis on your source code and start the web server to provide a convenient view of the results. Open http://localhost:8080 in your browser to examine the found problems and performed checks. Here you can also reconfigure the analysis. See the User interface overview for details. When done, you can stop the web server by pressing Ctrl-C in the Docker console.

Next steps

Last modified: 14 October 2021