Linting and Formatting
Local Linting with Flake8 (VSC):
- Install Flake8 Extension
If python environment included flake8 already, it will automatically start linting the python files
Otherwise: Install Flake8 (Documentation)
Qunicorn Flake8 Settings can be found in
.flake8Display the current problems in the console:
flake8 .Check for Linting Errors (black & flake) with:
poetry run invoke check-linting
Flake8 Settings
Ignore single line: Add
# noqato the end of the lineIgnore specific error in a single line: Add
# noqa E711to the end of the line (replaceE711with the error code to suppress)Ignore whole file: Add
# flake8: noqaat the start of the fileIgnore certain warnings in files, add to
.flake8file
per-file-ignores =
filename:ErrorCode
e.g.:
per-file-ignores =
__init__.py:F401,F403,C901
Formatting with black
Install Black
pip install black
Check if there are open black warnings/errors in the project
black --check .
Run Black on a single file:
black filename
OR: Run Black on directory or directly on the current navigated folder
black directory/
black .
This will automatically format the selected files
Files or directories can also be excluded
black --check --extend-exclude="regex" directory
To get more information on the progress add
--verboseoption
Automatic Formatting on Save
- In Pycharm:
Strg + Alt + A → Search for “Actions on Save” → check “Reformat code” and “Optimize imports”
Furthermore: Disable Line breaks reformatting and increase hard wrap