Code style¶
Automatic formatting and linting of the code can be performed with either nox
or pre-commit
.
Lint with nox¶
After successful setup, nox
sessions can be executed to perform lint checks:
nox -s lint
This runs isort
, black
, flake8
and codespell
and fixes almost all formatting and linting problems automatically, but a small minority has to be fixed by hand (e.g. unused imports).
Note
To reuse current virtual environment and avoid long installation time use -R
option:
nox -R -s lint
Note
pre-commit can also be run from nox:
nox -s pre_commit
Lint with pre-commit¶
Alternatively, you can use pre-commit to perform the same job.
Pre-commit
hooks need to be installed:
pre-commit install
Now, each use of git commit
in the shell will trigger actions defined in the .pre-commit-config.yaml
file.
Pre-commit can be easily disabled with a similar command:
pre-commit uninstall
If you wish to run pre-commit
asynchronously, then use:
pre-commit run --all-files
Note
pre-commit
by default also runs nox
with isort
,flake8
, black
and codespell
sessions
Tools¶
Tools used in project for maintaining code style:
Nox
is a tool, which simplifies management of Python testing. Visit nox websitePre-commit
is a framework for managing and maintaining multi-language pre-commit hooks. Visit pre-commit websiteBlack
is a code formatter. Visit black websiteFlake8
is a tool capable of linting, styling fixes and complexity analysis. Visit flake8 websiteIsort
is a Python utility to sort imports alphabetically. Visit isort websiteCodespell
is a Python tool to fix common spelling mistakes in text files Visit codespell repository