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:


Last update: 2024-09-17