Repository navigation
Commit 92421be
build(tox): write
The `ruff`, `format`, `mypy`, `html`, and `misc` environments are each
meant to run once, on the first available interpreter in a preference
order: Python 3.9 first, then 3.10, 3.11, 3.12, and 3.8. They wrote
that as `base_python = py{39,310,311,312,38}`, a form introduced in
62c024e (gitpython-developers#1693).
tox expands braces in generative environment lists and section names,
such as `env_list = py{38,...}` and `[testenv:py{38,39,310}]` in this
file, and in factor conditions, but not in the values of settings
like `base_python`. There, it just splits on commas, giving the five
specs `py{39`, `310`, `311`, `312`, and `38}`. The first and last are
not valid interpreter specs, so 3.9 and 3.8 were never candidates.
The bare `310`, `311`, and `312` are accepted as version specs, so the
environments still ran if 3.10, 3.11, or 3.12 was found. If none was,
the environment did not run: with tox 4.11.3 running on 3.13 and only
3.9 on `PATH`, it reported "skipped because could not find python
interpreter with spec(s): py{39, 310, 311, 312, 38}". Since tox 4.56.0
changed the default of `skip_missing_interpreters` to false, current
tox fails it instead.
Write each list as `py39, py310, py311, py312, py313, py314, py315`,
the documented form for several `base_python` values, of which the
first one found is used. This keeps the intended order, except that
3.8 is left out, and adds the newer versions at the end.
62c024e listed as fallbacks all the Python versions the project
supported, but the lists were not extended when da58f39 (gitpython-developers#2196) added
3.13, 3.14, and 3.15 to `env_list`. So on a system with only 3.13 or
later, these environments could not run at all. With only 3.13, 3.14,
and 3.15 available, a probe with `py39, py310, py311, py312` was skipped
with tox 4.23.2 and virtualenv 20.28.1 and failed with tox 4.67.1 and
virtualenv 21.14.13, while the full list ran on 3.13 with both.
The brace form never selected 3.8, so leaving it out takes away
nothing that worked, and listing it would now cause failures. Since
virtualenv 21.5.0, virtualenv cannot create Python 3.8 environments.
tox 4.56.0 and later work around that by bootstrapping an older
virtualenv, but only when the installed virtualenv can create none of
the `base_python` candidates, which is not the case for a list that
also names newer versions. Current virtualenv also tries the first
listed interpreter last, as described below, so 3.8 would be tried
before 3.9. With tox 4.67.1 and virtualenv 21.14.13 and only 3.8 and
3.9 available, a probe with `py39, py310, py311, py312, py38`
accepted 3.8 and then failed with "could not find python interpreter
matching any of the specs". With `py39, py310, py311, py312`, it ran
on 3.9.
Even where 3.8 environments can be created, `mypy` and `html` would
not work as intended on 3.8. The `test` extra installs mypy only on
3.9 and later, so the `mypy` environment would not have the `mypy`
command it runs, and `ignore_outcome` would turn that failure into a
warning. The `doc` group's Sphinx requirement also applies only on
3.9 and later, so `html` would build with whatever Sphinx version the
other documentation dependencies happened to pull in.
Checked with a minimal tox project whose only environment prints its
interpreter's version, with Python 3.9 and 3.12 on `PATH` and tox
itself running on 3.13.
| Tooling | Brace form | Comma form |
|----------------------------------|------------|------------|
| tox 4.11.3, virtualenv 20.24.5 | 3.12 | 3.9 |
| tox 4.23.2, virtualenv 20.28.1 | 3.12 | 3.9 |
`tox config` shows the intended entries for each environment.
With tox 4.23.2 and virtualenv 20.28.1, `tox -e ruff` and
`tox -e format` with this `tox.ini` ran on Python 3.9.6 and passed.
With tox 4.67.1, each of the five environments also ran and passed on
each of Python 3.13.17, 3.14.9, and 3.15.1, selected with
`-x testenv:<name>.base_python=py313` and so on. `html` reports no
Sphinx warnings on 3.13, but 13 on each of 3.14 and 3.15, all about
`__annotate_func__`, which Python 3.14 adds to the `__dict__` of
classes with annotations. The build used Sphinx 7.4.7, as the `doc`
group requires Sphinx below 8. CI's documentation build on 3.14
reports the same 13 warnings.
Current virtualenv does not keep this order. tox passes the
`base_python` list to virtualenv in `VIRTUALENV_PYTHON`, and since
virtualenv 20.29, when that variable is set, virtualenv moves the first
spec to the end of the list. That change, pypa/virtualenv@bc7a91a5
(pypa/virtualenv#2821), was meant to let a `--python` option take
precedence over a single interpreter set in the variable. So with tox
4.67.1 and virtualenv 21.14.13, the first listed interpreter is tried
last: a probe with `py39, py312, py311` ran on 3.12, and one with
`py312, py39` ran on 3.9. This is a problem in how tox and virtualenv
interact, not in this configuration. With current versions, these
environments are tried on 3.9 only if none of 3.10 through 3.15 is
found.
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>base_python fallbacks as comma-separated lists1 parent e1638a5 commit 92421be
1 file changed
Lines changed: 5 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
| 49 | + | |
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
| 57 | + | |
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
| 67 | + | |
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| |||
0 commit comments