I am implementing a reusable noxfile, my goal is that the different Python components of my project can have the same workflow for testing, linting, etc.
To do this, I created a nox_plugin module containing this generic noxfile.py (this is a sample):
import nox
@nox.session(reuse_venv=True)
def tests(session: nox.Session) -> None:
"""
Run unit tests with required coverage.
"""
session.install("-r", "dev-requirements.txt")
session.run("coverage", "run", "-m", "pytest", "src")
session.run("coverage", "json")
session.run("coverage", "report")
session.run("coverage-threshold")
I can package this module into a wheel that I can reuse by simply using the following noxfile.py in other projects:
from nox_plugin import tests
and executing the nox command.
However, I have to redefine the pyproject.toml sections for the coverage and coverage-threshold tools in all the modules using the nox_plugin package:
# Coverage configuration
[tool.coverage.run]
branch = true
omit = ["*__init__.py"]
include = ["src/main/*"]
[tool.coverage.report]
precision = 2
# Coverage-threshold configuration
[tool.coverage-threshold]
line_coverage_min = 90
file_line_coverage_min = 90
branch_coverage_min = 80
file_branch_coverage_min = 80
I would like to define default values for those sections in my nox_plugin module. This way, I can have a default configuration followed by all repos (for example, the same linting threshold for all code, or the same coverage thresholds).
pyproject.tomlif any option is defined and read the values, then I would write it so that all options are passed via the command line in thesession.run()calls, of course the plugin would pass either the default option or the option found in the TOML file. But... there are a couple of blockers that could exist. One is that maybe not all options are applicable on the command line. And second, there are probably more ways for users to set options than via the TOML file.