Code style¶
Nox or pre-commit performs automatic formatting and linting of the code.
Lint with nox¶
After successful setup, Nox sessions can be executed to perform lint checks:
nox -s lint
This runs ruff and codespell and fixes almost all formatting and linting problems automatically.
Note
To reuse the current virtual environment and avoid lengthy installation processes, use the -R flag:
nox -R -s lint
Note
pre-commit can also be run from nox:
nox -s pre_commit
Lint with pre-commit¶
Alternatively, 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 is easily deactivated with a similar command:
pre-commit uninstall
If you wish to run pre-commit asynchronously, use:
pre-commit run --all-files
Note
pre-commit by default also runs nox with ruff and codespell sessions.
Tools¶
Tools used in the Topwrap project for maintaining the code style:
noxis a tool, which simplifies management of Python testing.pre-commitis a framework for managing and maintaining multi-language pre-commit hooks.ruffis a Python linter and code formatter.codespellis a Python tool to fix common spelling mistakes in text files