Coding Style Guide#
pyvisgrid follows the PEP8 style guide for Python. This is enforced via the Ruff
linter and code formatter and through the pre-commit hook set up in Further Setup.
API Documentation Style#
All functions, classes including their methods, and modules should contain API documentation
in their docstrings. We’re adhering to the numpydoc style guide, that in it’s
simplest format consists of a summary, and a description of parameters and
return values. Please make sure you include types for each argument if possible.
Type Hinting#
We follow PEP484 and PEP544 for type hinting. Please make sure you add type hints to function definitions whenever possible.
Unit Tests#
All code you write should have associated unit tests, i.e. persistent tests for a single functionality or library (e.g. functions, methods, or classes). The tests are used to ensure the code works and handles exceptions as expected, and to reduce bugs.
pyvisgrid uses pytest as testing framework (see Testing). All tests
are located in the tests directory in the radionets-project/pyvisgrid
main repository. Separate files are used for each module.
When developing new features, make testing part of that development process. Make sure to write unit tests, that…
At least execute all new functionalities
Test I/O operations if required, e.g. through simple test inputs
Cover edge and exception cases
Additionally, any time you find and fix a bug, it is also best practice to add a unit test to ensure that specific bug does not appear again.
To measure the test coverage[1] of the codebase, we use Coverage.py
with pytest-cov as plugin for pytest. pytest-cov can be invoked
using the --cov flag:
$ pytest --cov
Coverage is also automatically reported using Codecov with our CI:
Further, we also use pytest-xdist to allow distributing tests
across multiple CPUs to speed up test execution, e.g. using all available CPUs:
$ pytest -n auto