Skip to content

Commit 225e228

Browse files
authored
πŸ› fix(config): resolve base_python from new-style version factors (#3846)
1 parent ae05f2a commit 225e228

3 files changed

Lines changed: 24 additions & 5 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
New-style version factors (e.g., ``3.10-tests``) now correctly set ``base_python`` - by :user:`gaborbernat`.

β€Žsrc/tox/tox_env/python/api.pyβ€Ž

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def version_dot(self) -> str:
6767
r"""
6868
^
6969
( (?P<impl> cpython | pypy ) - )? # optional interpreter prefix with dash
70-
(?P<version> [2-9] \. [0-9]+ ) # explicit major.minor version
70+
(?P<version> [23] \. [0-9]+ ) # explicit major.minor version (Python 2.x or 3.x)
7171
(?P<threaded> t? ) # optional free-threaded suffix
7272
$
7373
""",
@@ -180,15 +180,18 @@ def _base_python_default(self, conf: Config, env_name: str | None) -> list[str]:
180180
@classmethod
181181
def extract_base_python(cls, env_name: str) -> str | None:
182182
candidates: list[str] = []
183-
match = PY_FACTORS_RE_EXPLICIT_VERSION.match(env_name)
184-
if match:
183+
if match := PY_FACTORS_RE_EXPLICIT_VERSION.match(env_name):
185184
found = match.groupdict()
186185
candidates.append(f"{'pypy' if found['impl'] == 'pypy' else ''}{found['version']}{found['threaded']}")
187186
else:
188187
for factor in env_name.split("-"):
189-
match = PY_FACTORS_RE.match(factor)
190-
if match:
188+
if match := PY_FACTORS_RE.match(factor):
191189
candidates.append(factor)
190+
elif match := PY_FACTORS_RE_EXPLICIT_VERSION.match(factor):
191+
found = match.groupdict()
192+
candidates.append(
193+
f"{'pypy' if found['impl'] == 'pypy' else ''}{found['version']}{found['threaded']}"
194+
)
192195
if candidates:
193196
if len(candidates) > 1:
194197
msg = f"conflicting factors {', '.join(candidates)} in {env_name}"

β€Žtests/tox_env/python/test_python_api.pyβ€Ž

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ def test_conflicting_base_python_factor() -> None:
4545
Python.extract_base_python(name)
4646

4747

48+
def test_conflicting_base_python_factor_explicit_version() -> None:
49+
with pytest.raises(ValueError, match=r"conflicting factors 3\.10, 3\.11 in 3\.10-3\.11"):
50+
Python.extract_base_python("3.10-3.11")
51+
52+
53+
def test_conflicting_base_python_factor_mixed_style() -> None:
54+
with pytest.raises(ValueError, match=r"conflicting factors py310, 3\.11 in py310-3\.11"):
55+
Python.extract_base_python("py310-3.11")
56+
57+
4858
def test_build_wheel_in_non_base_pkg_env(
4959
tox_project: ToxProjectCreator,
5060
patch_prev_py: Callable[[bool], tuple[str, str]],
@@ -142,6 +152,11 @@ def test_diff_msg_no_diff() -> None:
142152
("2.7t", "2.7t"),
143153
("pypy-3.10", "pypy3.10"),
144154
("pypy-3.10t", "pypy3.10t"),
155+
("3.10-tests", "3.10"),
156+
("3.10t-tests", "3.10t"),
157+
("tests-3.10", "3.10"),
158+
("tests-3.10t", "3.10t"),
159+
("foo-3.14-bar", "3.14"),
145160
],
146161
ids=lambda a: "|".join(a) if isinstance(a, list) else str(a),
147162
)

0 commit comments

Comments
Β (0)