Code Quality
In an active development shell, the following make targets are available and act on all .py files under src/:
Command |
Description |
|---|---|
|
Formats code and imports with ruff, docstrings with docformatter, and JSON documents with jq |
|
Lints code with ruff |
|
Typechecks code with mypy |
|
Runs unit tests and reports coverage with pytest and coverage |
|
Equivalent to |
Configuration for these tools is provided by the file src/pyproject.toml.
The order of the targets above is intentional:
make formatwill complain about certain kinds of syntax errors that would cause all the remaining code-quality tools to fail (and that could change line numbers reported by other tools, if it ran after them).
make lintprovides a good first check for obvious errors and anti-patterns in the code.
make typecheckoffers a more nuanced look at interfaces between functions, methods, etc. and may spot issues missed by the linter.
make unittestprovides higher-level semantic-correctness checks once code syntax and typing is deemed correct.
All the above tests are executed by the CI system when code is merged to specific git branches and when a conda package is built for release. To ensure that these processes succeed, be sure to run all the tests in a development shell before opening a pull request, and throughout the PR’s lifecycle as subsequent changes are made. CI will reject unformatted code, so also run make format and commit any changes it makes. A useful development idiom is to periodically run make format && make test to perform a full code-quality sweep through the code.
The uwtools repository has standardized 100% unit-test coverage, enforced by make unittest and its configuration in pyproject.toml. Please help maintain this high standard.