Skip to content

Commit ea2dedb

Browse files
EliahKaganclaude
andcommitted
build(tox): let older tox provision one that reads [tool.tox]
tox older than 4.21 does not read native TOML from `[tool.tox]`, so with the configuration there, it cannot see `requires` and provision a newer tox. It looks only at `legacy_tox_ini`, an INI string in `[tool.tox]`, finds none, and assumes an empty configuration. Plain `tox` then passes without testing anything: with tox 4.11.3, it reported "assuming empty tox.ini", installed GitPython with `gitdb` from PyPI into a default `py` environment that has no commands, and exited with status 0. `tox -e ruff` failed with "provided environments not found in configuration file". Add a `legacy_tox_ini` for older tox. Whatever older tox reads, tox 4.21 to 4.40 also use instead of the native tables, because they prefer `legacy_tox_ini` when both are present. Only tox 4.41 and later prefer the native tables and ignore it. `tox.ini` and `setup.cfg` are no alternative, since even current tox reads them first. So the one stub has to work for every tox before 4.41. It has four parts: - `requires = tox>=4.41`, so that each such tox installs and runs tox 4.41 or later. Raise the native `requires` to match, since only tox 4.41 and later read it now. A stub requiring only 4.22 was not enough: tox 4.22.0, 4.23.2, 4.25.0, 4.30.0, and 4.40.0 found that met, and saw an empty configuration. - An `env_list` naming every environment, including `gix`. tox 4.11.3 and the later versions tried, though not 4.0.0 or 4.4.12, check the names given to `-e` against the configuration they read, before provisioning, so without this, `tox -e ruff` still failed with "provided environments not found". The list must be kept in step with the native tables. A missing name makes older tox reject that environment, rather than run anything else. - A `[testenv]` whose command always fails, saying that tox 4.41 or later is needed. A tox that provisions never runs it. But if the stub's `requires` were removed or lowered, older tox would run the stub's environments instead: tox 4.40.0, given the stub without `requires`, installed GitPython, ran nothing, and reported success. - `[testenv:.tox]` with `base_python` listing Python 3.10 and later. tox provisions into its `.tox` environment, by default with the Python it runs on, and tox 4.41 needs Python 3.10. Without this, tox 4.30.0 running on Python 3.9 failed to install a newer tox ("ResolutionImpossible"). This list, too, must be kept in step with the Python versions tested. So a part that is missing or wrong makes older tox fail, not pass without testing anything. The README now says what this needs: a download, and Python 3.10 or later. The stub is INI, the format tox's documentation calls deprecated, because older tox reads nothing else. Comments on it say so, and that it can be removed once tox older than 4.41 need not be supported. Checked in copies of the project with `tox config -e gix -k description` and `tox -e ruff`: - With tox running on Homebrew's Python 3.13, tox 4.0.0, 4.5.0, 4.11.3, 4.15.0, 4.20.0, 4.21.0, 4.21.2, 4.22.0, 4.25.0, 4.30.0, 4.35.0, and 4.40.0 provisioned a newer tox, which showed the native description of `gix` and passed `ruff`. tox 4.41.0, 4.50.0, 4.60.0, and 4.67.1 did the same without provisioning. - With tox running on Python 3.9.6, tox 4.0.0, 4.11.3, 4.20.0, 4.21.0, 4.22.0, 4.25.0, and 4.30.0 did the same, with the newer tox on Python 3.13. So did all of those but 4.30.0 on Python 3.8.20, which that version does not support. - With tox 4.20.0 on Python 3.9, plain `tox --notest` provisioned a newer tox, which set up exactly the environments in the native `env_list`. - With the stub's `requires` line removed, tox 4.40.0 on Python 3.13, and tox 4.30.0 and 4.20.0 on Python 3.9, failed each environment with the guard's message. - tox 3.28.0 worked when running on Python 3.13, but failed on Python 3.9. tox 3 knows only `basepython`, not `base_python`, so it provisions with the Python it runs on. `tox list` fails after provisioning with tox 4.6.0 to 4.14.1, with "AttributeError: 'Parsed' object has no attribute 'list_dependencies'" from inside those versions. tox 4.5.0 and 4.14.2 list the environments, and running environments works with all of them. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 1b69c99 commit ea2dedb

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ Specific tools are all configured in the [`./pyproject.toml`](https://github.com
232232
Orchestration tools:
233233

234234
- Configuration for `pre-commit` is in the [`./.pre-commit-config.yaml`](https://github.com/gitpython-developers/GitPython/blob/main/.pre-commit-config.yaml) file.
235-
- Configuration for `tox` is in the `[tool.tox]` table of [`./pyproject.toml`](https://github.com/gitpython-developers/GitPython/blob/main/pyproject.toml), which requires tox 4.22 or later.
235+
- Configuration for `tox` is in the `[tool.tox]` table of [`./pyproject.toml`](https://github.com/gitpython-developers/GitPython/blob/main/pyproject.toml), which requires tox 4.41 or later. An older tox 4 installs and runs a newer one automatically, if it can download it and Python 3.10 or later is available for it.
236236
- Configuration for GitHub Actions (CI) is in files inside [`./.github/workflows/`](https://github.com/gitpython-developers/GitPython/tree/main/.github/workflows).
237237

238238
### Contributions

‎pyproject.toml‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,28 @@ lint.unfixable = [
157157
]
158158

159159
[tool.tox]
160-
requires = ["tox>=4.22"]
160+
requires = ["tox>=4.41"]
161+
# tox older than 4.41 uses only this: before 4.21 it cannot read the native tables, and 4.21 to 4.40
162+
# prefer this when both are present. It makes that tox install and run tox 4.41 or later, which uses
163+
# the native tables instead. (tox 3 also reads it, but can install tox 4.41 only when itself running
164+
# on Python 3.10 or later, since it ignores `base_python`.) It is INI, which tox deprecates, because
165+
# older tox reads nothing else. It can be removed once tox older than 4.41 need not be supported.
166+
legacy_tox_ini = """
167+
[tox]
168+
requires = tox>=4.41
169+
# Older tox accepts only environment names it can see. Keep these in step with the tables below.
170+
env_list = py{38,39,310,311,312,313,314,315}, ruff, format, mypy, html, misc, gix
171+
172+
# If a tox runs an environment from here, rather than a newer tox from the native tables, fail.
173+
[testenv]
174+
skip_install = true
175+
commands = python -c "raise SystemExit('This needs tox 4.41 or later, which tox did not install.')"
176+
177+
# tox 4.41 needs Python 3.10 or later, which may not be the Python running the older tox.
178+
# Keep these in step with the Python versions tested, from 3.10 on.
179+
[testenv:.tox]
180+
base_python = py314, py313, py312, py311, py310, py315
181+
"""
161182
# Skip environments whose Python is not installed.
162183
skip_missing_interpreters = true
163184
env_list = [

0 commit comments

Comments
 (0)