How to configure your IDE or editor for use with our projects¶
We use the poetry tool to manage dependencies in many of our Python projects. This guide covers how to best configure your editor or IDE to work well with our way of writing Python packages.
If your preferred editor is not present in the list below, feel free to contribute a section.
Visual Studio Code¶
This section covers configuration appropriate for Visual Studio Code (VSCode). It does not attempt to be comprehensive since fine-scale IDE configuration tends to be personal to each developer.
Python projects using poetry¶
This section is applicable to webapps following our standard boilerplate or Python libraries using
poetry for packaging. An indication of this is a poetry.lock
file in the root of the repository.
VSCode has full support for the poetry tool as part of the standard Python extension. We recommend installing at least the Python and Docker extensions along with, optionally, the "Pylance", "Flake8" and "Mypy Type Checker" extensions.
To configure VSCode to use the poetry-created virtualenv:
- If you have not yet done so, run
poetry install
in the application repository's directory. - In VSCode, select File > Open Folder... from the menu and select the application repository's directory.
- Open the command palette via Ctrl-Shift-P, or ⌘-Shift-P on a Mac.
- Type "Python: Select Interpreter" and select the command from the drop-down menu.
- Select the interpreter marked "poetry".
But I like my virtualenvs in the project folder!
Running poetry config virtualenvs.in-project true
will configure poetry to create virtualenvs
within the application root
directory in a directory
called .venv
. VSCode will discover the virtualenv in .venv
automatically without explicit
configuration.
To configure VSCode to run tests:
- Ensure that you have VSCode configured for poetry as described above.
- Open the command palette as described above and run the command "Python: Configure Tests".
- Select "pytest" and then select ". (root directory)".
- Click the "testing" icon in the sidebar. It is a laboratory flask.
- Click the "play" icon next to tests to run them.
Read more about testing Python applications in the VSCode documentation.