From 709c0be4a2dca3ceef04aae432417fb76f2930c7 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 18 Oct 2025 16:08:15 -0400 Subject: [PATCH] update for nox 2025-10-16 includes fix for https://github.com/wntrblm/nox/pull/999 Change-Id: Id38dc01a1fb8a7446e427a8cf9a0cae2db6c4a3b --- noxfile.py | 2 ++ tools/toxnox.py | 50 +++++++++++++++++++++---------------------------- 2 files changed, 23 insertions(+), 29 deletions(-) diff --git a/noxfile.py b/noxfile.py index 12aace66..965c5875 100644 --- a/noxfile.py +++ b/noxfile.py @@ -10,6 +10,8 @@ import sys import nox from packaging.version import parse as parse_version +nox.needs_version = ">=2025.10.16" + if True: sys.path.insert(0, ".") from tools.toxnox import tox_parameters diff --git a/tools/toxnox.py b/tools/toxnox.py index 546ef214..891fc70f 100644 --- a/tools/toxnox.py +++ b/tools/toxnox.py @@ -15,6 +15,7 @@ import re import sys from typing import Any from typing import Callable +from typing import Generator from typing import Sequence import nox @@ -70,31 +71,10 @@ def tox_parameters( PY_RE = re.compile(r"(?:python)?([234]\.\d+(t?))") - def _is_py_version(token): + def _is_py_version(token: str) -> bool: return bool(PY_RE.match(token)) - def _expand_python_version(token): - """expand pyx.y(t) tags into executable names. - - Works around nox issue fixed at - https://github.com/wntrblm/nox/pull/999 by providing full executable - name - - """ - if sys.platform == "win32": - return token - - m = PY_RE.match(token) - - # do this matching minimally so that it only happens for the - # free-threaded versions. on windows, the "pythonx.y" syntax doesn't - # work due to the use of the "py" tool - if m and m.group(2) == "t": - return f"python{m.group(1)}" - else: - return token - - def _python_to_tag(token): + def _python_to_tag(token: str) -> str: m = PY_RE.match(token) if m: return f"py{m.group(1).replace('.', '')}" @@ -109,7 +89,11 @@ def tox_parameters( else: must_be_present = None - def _recur_param(prevtokens, prevtags, token_lists): + def _recur_param( + prevtokens: list[str], + prevtags: list[str], + token_lists: Sequence[Sequence[str]], + ) -> Generator[tuple[list[str], list[str], str], None, None]: if not token_lists: return @@ -181,9 +165,7 @@ def tox_parameters( ) params = [ - nox.param( - *[_expand_python_version(a) for a in args], tags=tags, id=ids - ) + nox.param(*args, tags=tags, id=ids) for args, tags, ids in _recur_param([], [], token_lists) if filter_ is None or filter_(**dict(zip(names, args))) ] @@ -195,14 +177,24 @@ def tox_parameters( def extract_opts(posargs: list[str], *args: str) -> tuple[list[str], Any]: + """Pop individual flag options from session.posargs. + Returns a named tuple with the individual flag options indicated, + as well the new posargs with those flags removed from the string list + so that the posargs can be forwarded onto pytest. + + Basically if nox had an option for additional environmental flags that + didn't require putting them after ``--``, we wouldn't need this, but this + is probably more flexible. + + """ underscore_args = [arg.replace("-", "_") for arg in args] - return_tuple = collections.namedtuple("options", underscore_args) + return_tuple = collections.namedtuple("options", underscore_args) # type: ignore # noqa: E501 look_for_args = {f"--{arg}": idx for idx, arg in enumerate(args)} return_args = [False for arg in args] - def extract(arg: str): + def extract(arg: str) -> bool: if arg in look_for_args: return_args[look_for_args[arg]] = True return True -- 2.47.3