Skip to content

Commit fc5f5e9

Browse files
committed
Improve tox environment name parsing
Closes #38, #50.
1 parent 6af0c15 commit fc5f5e9

3 files changed

Lines changed: 20 additions & 6 deletions

File tree

‎CHANGES.rst‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ Changelog
44
0.24.1 (unreleased)
55
-------------------
66

7-
- Nothing changed yet.
7+
- Improve tox environment name parsing: accept dotted names (e.g. py3.14),
8+
more specific pypy versions (pypy311). `GH #38
9+
<https://github.com/mgedmin/check-python-versions/issues/38>`_ and `GH #50
10+
<https://github.com/mgedmin/check-python-versions/issues/50>`_.
811

912

1013
0.24.0 (2025-11-13)

‎src/check_python_versions/sources/tox.py‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,18 @@ def tox_env_to_py_version(env: str) -> Version | None:
101101
102102
If the environment name has dashes, only the first part is considered,
103103
e.g. py34-django20 becomes '3.4', and jython-docs becomes 'jython'.
104+
(This is probably incorrect, I think tox itself allows the Python
105+
factor to be in any position, e.g. orange-py3.11.)
104106
"""
105107
if '-' in env:
106108
# e.g. py34-coverage, pypy-subunit
107109
env = env.partition('-')[0]
108-
if env.startswith('pypy'):
109-
return Version.from_string('PyPy' + env[4:])
110-
elif env.startswith('py') and len(env) >= 4 and env[2:].isdigit():
111-
return Version.from_string(f'{env[2]}.{env[3:]}')
110+
if env.startswith('pypy3'):
111+
return Version.from_string('PyPy3')
112+
if env == 'pypy' or env.startswith('pypy2'):
113+
return Version.from_string('PyPy')
114+
elif m := re.match(r'^py([2-3])[.]?([0-9]+)t?$', env):
115+
return Version.from_string(f'{m[1]}.{m[2]}')
112116
else:
113117
return None
114118

‎tests/sources/test_tox.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,16 @@ def test_brace_expand(s, expected):
9191
@pytest.mark.parametrize('s, expected', [
9292
('py36', '3.6'),
9393
('py37-lint', '3.7'),
94-
('py310', '3.10'), # future-proofness!
94+
('py3.9', '3.9'),
95+
('py310', '3.10'),
96+
('py3.10', '3.10'),
97+
('py314t', '3.14'),
98+
('py3.14t', '3.14'),
9599
('pypy', 'PyPy'),
100+
('pypy2', 'PyPy'),
96101
('pypy3', 'PyPy3'),
102+
('pypy311', 'PyPy3'),
103+
('pypy3.11', 'PyPy3'),
97104
('pylint', None),
98105
('flake8', None),
99106
])

0 commit comments

Comments
 (0)