diff --git a/.config/dictionary.txt b/.config/dictionary.txt index c1e058d..fd4a11b 100644 --- a/.config/dictionary.txt +++ b/.config/dictionary.txt @@ -16,7 +16,6 @@ distros facelessuser fontawesome gitreview -hashseed hexsha htmlproofer inlinehilite @@ -29,7 +28,6 @@ posargs prek pymdownx pypackage -showconfig showlocals ssbarnea superfences diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index 98f7044..4d32d67 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -142,7 +142,7 @@ jobs: - name: Install tox run: | python3 -m pip install --upgrade pip - python3 -m pip install --upgrade "tox>=4.0.0" "tox-uv>=1.25.0" "uv>=0.6.6" + python3 -m pip install --upgrade "tox>=4.47.3" "tox-uv>=1.25.0" "uv>=0.6.6" - name: Log installed dists run: python3 -m pip freeze --all diff --git a/pyproject.toml b/pyproject.toml index e564dd5..9c3fb13 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -333,12 +333,12 @@ commands = [ "-m", "pytest", { default = [ - "-ra", + "-v", + "-rA", "--showlocals", "--doctest-modules", "--durations=10", - "-m", - "not eco" + "--durations-min=5", ], extend = true, replace = "posargs" } ], [ diff --git a/samples/integration/ansible-lint.txt b/samples/integration/ansible-lint.txt index 82cc980..e69e916 100644 --- a/samples/integration/ansible-lint.txt +++ b/samples/integration/ansible-lint.txt @@ -1,13 +1,22 @@ alerts build changelog +devel +docs drafts +eco generate_docs get-version +hook install install-reqs lint +lint2 +lower +pkg prs +py +schemas test test-eco test-hook diff --git a/src/mk/tools/tox.py b/src/mk/tools/tox.py index 8554517..2516091 100644 --- a/src/mk/tools/tox.py +++ b/src/mk/tools/tox.py @@ -2,17 +2,14 @@ from __future__ import annotations -import logging +import json import os -import re -import shlex import shutil -import sys -from configparser import ConfigParser, ParsingError from pathlib import Path +import tomllib + from mk.exec import run_or_fail -from mk.text import strip_ansi_escape from mk.tools import Action, Tool @@ -20,58 +17,28 @@ class ToxTool(Tool): name = "tox" def is_present(self, path: Path) -> bool: + pyproject = Path(path) / "pyproject.toml" if os.path.isfile(os.path.join(path, "tox.ini")): if not shutil.which("tox"): msg = "Tox config found but tox is not installed. Please install it with `uv pip install tox`." raise RuntimeError(msg) return True + if pyproject.is_file(): + data = tomllib.loads(pyproject.read_text()) + if "tool" in data and "tox" in data["tool"]: + return True return False def actions(self) -> list[Action]: - # -a is not supported by tox4! actions: list[Action] = [] - cp = ConfigParser(strict=False, interpolation=None) - env_overrides = {"PY_COLORS": "0"} result = run_or_fail( - ["tox", "-qq", "--colored", "no", "--hashseed", "1", "--showconfig"], - env_overrides=env_overrides, + "uv tool run --with 'tox>=4.48.1' tox config --format=json --color=no -qq", tee=False, ) - tox_cfg = result.stdout or "" - - # workaround for https://github.com/tox-dev/tox/issues/2030 - # we remove all lines starting with .tox from output - tox_cfg = re.sub( - r"^\.tox[^\r\n]*\n$", - "", - strip_ansi_escape(tox_cfg), - flags=re.MULTILINE, - ) - - # now tox_cfg should have a valid ini content - try: - cp.read_string(tox_cfg) - except ParsingError: - logging.fatal( - "Unable to parse tox output from command: %s", - shlex.join(result.args), - ) - print(tox_cfg, file=sys.stderr) - sys.exit(22) - for section in cp.sections(): - if section.startswith("testenv:"): - _, env_name = section.split(":") - # we ignore hidden envs like implicit .pkg: - if not env_name.startswith("."): - actions.append( - Action( - name=env_name, - tool=self, - description=cp[section]["description"], - args=[env_name], - ), - ) - + data = json.loads(result.stdout) + for name in data["env"]: + description = data["env"][name].get("description", None) + actions.append(Action(name=name, description=description, tool=self)) return actions def run(self, action: Action | None = None) -> None: