1515import sys
1616from typing import Any
1717from typing import Callable
18+ from typing import Generator
1819from typing import Sequence
1920
2021import nox
@@ -70,31 +71,10 @@ def tox_parameters(
7071
7172 PY_RE = re .compile (r"(?:python)?([234]\.\d+(t?))" )
7273
73- def _is_py_version (token ) :
74+ def _is_py_version (token : str ) -> bool :
7475 return bool (PY_RE .match (token ))
7576
76- def _expand_python_version (token ):
77- """expand pyx.y(t) tags into executable names.
78-
79- Works around nox issue fixed at
80- https://github.com/wntrblm/nox/pull/999 by providing full executable
81- name
82-
83- """
84- if sys .platform == "win32" :
85- return token
86-
87- m = PY_RE .match (token )
88-
89- # do this matching minimally so that it only happens for the
90- # free-threaded versions. on windows, the "pythonx.y" syntax doesn't
91- # work due to the use of the "py" tool
92- if m and m .group (2 ) == "t" :
93- return f"python{ m .group (1 )} "
94- else :
95- return token
96-
97- def _python_to_tag (token ):
77+ def _python_to_tag (token : str ) -> str :
9878 m = PY_RE .match (token )
9979 if m :
10080 return f"py{ m .group (1 ).replace ('.' , '' )} "
@@ -109,7 +89,11 @@ def _python_to_tag(token):
10989 else :
11090 must_be_present = None
11191
112- def _recur_param (prevtokens , prevtags , token_lists ):
92+ def _recur_param (
93+ prevtokens : list [str ],
94+ prevtags : list [str ],
95+ token_lists : Sequence [Sequence [str ]],
96+ ) -> Generator [tuple [list [str ], list [str ], str ], None , None ]:
11397
11498 if not token_lists :
11599 return
@@ -181,9 +165,7 @@ def _recur_param(prevtokens, prevtags, token_lists):
181165 )
182166
183167 params = [
184- nox .param (
185- * [_expand_python_version (a ) for a in args ], tags = tags , id = ids
186- )
168+ nox .param (* args , tags = tags , id = ids )
187169 for args , tags , ids in _recur_param ([], [], token_lists )
188170 if filter_ is None or filter_ (** dict (zip (names , args )))
189171 ]
@@ -195,14 +177,24 @@ def _recur_param(prevtokens, prevtags, token_lists):
195177
196178
197179def extract_opts (posargs : list [str ], * args : str ) -> tuple [list [str ], Any ]:
180+ """Pop individual flag options from session.posargs.
198181
182+ Returns a named tuple with the individual flag options indicated,
183+ as well the new posargs with those flags removed from the string list
184+ so that the posargs can be forwarded onto pytest.
185+
186+ Basically if nox had an option for additional environmental flags that
187+ didn't require putting them after ``--``, we wouldn't need this, but this
188+ is probably more flexible.
189+
190+ """
199191 underscore_args = [arg .replace ("-" , "_" ) for arg in args ]
200- return_tuple = collections .namedtuple ("options" , underscore_args )
192+ return_tuple = collections .namedtuple ("options" , underscore_args ) # type: ignore # noqa: E501
201193
202194 look_for_args = {f"--{ arg } " : idx for idx , arg in enumerate (args )}
203195 return_args = [False for arg in args ]
204196
205- def extract (arg : str ):
197+ def extract (arg : str ) -> bool :
206198 if arg in look_for_args :
207199 return_args [look_for_args [arg ]] = True
208200 return True
0 commit comments