2. Python Developer Environments
The IBCDFO repository includes a tox setup that defines a set of
predefined development tasks, each of which runs in a dedicated Python virtual
environment created and managed automatically by tox.
2.1. Development with tox
To set up tox for use with this repository, please follow the directions
included in the POptUS Developer Guide.
The following commands can be run from /path/to/IBCDFO/ibcdfo_pypkg:
tox -e coverageExecute the full test suite for the package and save coverage results.
The
COVERAGE_FILEenvironment variable can optionally be set to define the output file name. By default, results are written to.coverage_ibcdfo.Tests run the package’s code as it exists in the developer’s local clone so that coverage results accessed through web services such as CodeCov are clean and straightforward. This mimics an editable (developer) installation.
tox -e nocoverageExecute the full test suite using the code installed into a Python virtual environment by
tox. This mimics a standard installation from a package distribution (e.g., a wheel).
tox -e poundersExecute the test suite for the POUNDERS subpackage using the code installed into a Python virtual environment by
tox.
tox -e manifold_samplingExecute the test suite for the Manifold Sampling subpackage using the code installed into a Python virtual environment by
tox.
tox -e reportIntended to be run after or with
coverage.Display a coverage report for the package’s full test suite and generate XML- and HTML-format reports.
The
COVERAGE_XML_FILEandCOVERAGE_HTML_FILEenvironment variables can optionally be set to define output file names. Defaults arecobertura_ibcdfo.xmlandhtmlcov_ibcdfo.
tox -e checkRun code quality checks to report potential issues. The codebase satisfies IBCDFO coding standards if this and the
formattask both pass.
tox -e formatNOTE: This may modify Python code in your local clone.
Automatically reformat code in the package using the
blacktool. The codebase satisfies IBCDFO coding standards after applying this task and if thechecktask is still passing.
tox -e format_safeReport changes that would be made by the
blacktool without modifying files.
tox -e htmlGenerate and render IBCDFO documentation locally in HTML format.
Documentation is built from the local clone rather than an installed package, enabling fast, interactive documentation work.
Additionally, you can run multiple tasks together, such as
tox -e report,coverage.
Each task can be run as either tox -e <task> or tox -r -e <task>.
Developers are responsible for determining which is correct for their current
situation.
2.2. Direct use of tox venvs
Developers may directly use the virtual environments (venvs) created and
managed by tox. For example, the venvs created for the coverage and
html tasks can be especially useful, since IBCDFO is installed in
editable mode, facilitating interactive development and testing.
To run the full test suite during an interactive debugging session, developers
can create a clean coverage venv and activate it with
$ cd /path/to/IBCDFO/ibcdfo_pypkg
$ tox -r -e coverage
$ . ./.tox/coverage/bin/activate
and subsequently run the full test suite in the venv with
$ python -m unittest ibcdfo
A user could then, for example, alter POUNDERS code or its
TestPoundersSimple test and rerun just that test in the venv with
$ python -m unittest ibcdfo.pounders.tests.TestPoundersSimple
to quickly check the effect.