Development
How to contribute
See the Spicerack's Wikitech page.
Code style
This project uses the Python automatic code formatter black in conjunction with isort and the tests will enforce that all the Python files are formatted according to the defined style.
In order to automatically format the code while developing, it's possible to integrate black either with the editor/IDE of choice or directly into the git workflow:
For the editor/IDE integration see the black's related page and the isort's related one.
For the git workflow integration, that can be done either at commit time or at review time. To do so create either a
pre-commit
or apre-review
executable hook file inside the.git/hooks/
directory of the project with the following content:#!/bin/bash tox -e py3-format
The
pre-commit
hook will be executed at every commit, while thepre-review
one when runninggit review
.If not looking for an automated integration, it's always possible to just manually format the code running:
tox -e py3-format
Git blame
In order to have a cleaner git blame, it might be useful to exclude some specific commits were just cosmetic changes were made from the history. To do that use:
git blame --ignore-revs-file .git-blame-ignore-revs <file>
Running tests
The tox
utility, a wrapper around virtualenv, is used to run the tests. To list the default environments that
will be executed when running tox
without parameters, run:
tox -lv
To list all the available environments:
tox -av
To run one specific environment only:
tox -e py39-flake8
To run all environments for a specific Python version, exclude all the others using the TOX_SKIP_ENV
environmental
variable that accepts a regular expression:
TOX_SKIP_ENV='py3(7|8|10)-.*' tox
It's possible to pass extra arguments to the underlying environment:
# Run only tests in a specific file:
tox -e py39-unit -- -k test_remote.py
# Run only one specific test:
tox -e py38-unit -- -k test_spicerack_netbox