1

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).

Kins
  • 547
  • 1
  • 5
  • 22
  • 1
    That seems a bit difficult to me. The way I would start such a task is that I would write the plugin so that it looks in `pyproject.toml` if any option is defined and read the values, then I would write it so that all options are passed via the command line in the `session.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. – sinoroc Mar 28 '23 at 15:16
  • From my point of view, this is not something that can be solved on StackOverflow. I feel like it would be quite a big task to implement this. -- If I were you I would try to get in touch with the *nox* and *coverage* communities to get some advice on how to get started, maybe they have better suggestions than the ones I gave you. -- If you start coding and encounter issues or blockers, feel free to post a new question on StackOverflow. -- But this question as it is now does not have its place on StackOverflow from my point of view (too big of a scope). – sinoroc Apr 20 '23 at 17:36

0 Answers0