diff --git a/.config/requirements.in b/.config/requirements.in index 35bed9a..38c8f19 100644 --- a/.config/requirements.in +++ b/.config/requirements.in @@ -5,6 +5,7 @@ click >= 7.1.2 colorama # for Windows diskcache >= 5.2.1 importlib-metadata +packaging pip>=21.0.1 # py_package pluggy pygments diff --git a/playbooks/test-integration.yml b/playbooks/test-integration.yml index 0b3c2c2..336aa8f 100644 --- a/playbooks/test-integration.yml +++ b/playbooks/test-integration.yml @@ -19,6 +19,8 @@ url: https://github.com/python/typeshed.git - name: flask-babel url: https://github.com/python-babel/flask-babel.git + - name: nox + url: https://github.com/wntrblm/nox tasks: - name: Show cache directory ansible.builtin.debug: diff --git a/pyproject.toml b/pyproject.toml index 58547fd..fd3b17b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,6 +58,7 @@ pre-commit = "mk.tools.pre_commit:PreCommitTool" shell = "mk.tools.shell:ShellTool" taskfile = "mk.tools.taskfile:TaskfileTool" tox = "mk.tools.tox:ToxTool" +nox = "mk.tools.nox:NoxTool" [tool.black] diff --git a/samples/integration/nox.txt b/samples/integration/nox.txt new file mode 100644 index 0000000..2adc53a --- /dev/null +++ b/samples/integration/nox.txt @@ -0,0 +1,18 @@ +build +conda_tests-3.10 +conda_tests-3.7 +conda_tests-3.8 +conda_tests-3.9 +cover +docs +install +lint +lint2 +test +tests-3.10 +tests-3.11 +tests-3.12 +tests-3.7 +tests-3.8 +tests-3.9 +uninstall diff --git a/src/mk/tools/nox.py b/src/mk/tools/nox.py new file mode 100644 index 0000000..e81fd42 --- /dev/null +++ b/src/mk/tools/nox.py @@ -0,0 +1,47 @@ +""" +Implementation of the nox tool support. +""" + +from __future__ import annotations + +import json +import logging +from pathlib import Path + +from packaging.version import Version + +from mk.exec import run_or_fail +from mk.tools import Action, Tool + +# This is the first version to support --json +_MINIMUM_NOX_VERSION = Version("2023.04.22") + + +class NoxTool(Tool): + name = "nox" + + def is_present(self, path: Path) -> bool: + return (path / "noxfile.py").is_file() + + def actions(self) -> list[Action]: + actions: list[Action] = [] + version: str = run_or_fail(["nox", "--version"], tee=False).stderr.strip() + if Version(version) < _MINIMUM_NOX_VERSION: + logging.warning( + "Failed to retrieve nox sessions: " + "nox version %s is too old. Minimum supported version is %s.", + version, + _MINIMUM_NOX_VERSION, + ) + return [] + results = run_or_fail(["nox", "--list", "--json"], tee=False) + data = json.loads(results.stdout) + actions = [ + Action(session["session"], tool=self, description=session["description"]) + for session in data + ] + return actions + + def run(self, action: Action | None = None) -> None: + cmd = ["nox"] if not action else ["nox", "-s", action.name] + run_or_fail(cmd, tee=True) diff --git a/tox.ini b/tox.ini index 4aa23b0..e246e32 100644 --- a/tox.ini +++ b/tox.ini @@ -5,7 +5,7 @@ envlist = pkg py integration -minversion = 3.23.0 +minversion = 4.11.3 isolated_build = true skip_missing_interpreters = false requires = @@ -100,11 +100,16 @@ description = Run integrations tests setenv = ANSIBLE_NOCOWS=1 ANSIBLE_FORCE_COLOR=1 +extras = + test deps = - -e .[test] ansible-core>=2.12 + nox commands = + ansible --version + nox --version mk test-integration +package = editable [testenv:pkg] description =