Skip to content

Commit 1b69c99

Browse files
EliahKaganclaude
andcommitted
build(tox): move the tox configuration into pyproject.toml
The tox configuration was kept in `tox.ini` because the only way tox could read it from `pyproject.toml` was `legacy_tox_ini`: the same INI text, stored as one big TOML string. Since tox 4.21.0, tox also reads native TOML from `[tool.tox]`, with real tables, arrays, and typed values, and tox's documentation now calls the INI format deprecated. `requires` already asks for tox 4.22 or later, for `dependency_groups`. Move every setting into `pyproject.toml` and remove `tox.ini`: - `[tox]` becomes `[tool.tox]`, `[testenv]` becomes `[tool.tox.env_run_base]`, and each `[testenv:<name>]` becomes `[tool.tox.env.<name>]`. - `env_list` lists each environment by name, since TOML has no brace expansion. The order is unchanged. - `[testenv:py{38,39,310}]` becomes three tables with the same settings. TOML has no generative table names. `env_base` templates (tox 4.46) would give the environments different names, and the `base` key works in TOML only since tox 4.39, so plain tables keep the same environments working on every tox that `requires` allows. - `{posargs}` and `{posargs:...}` become `replace = "posargs"` tables, with the `gix` environment's default arguments as `default`. - Commands become argument lists, so they no longer go through shell-like splitting. `{env_tmp_dir}` is still substituted inside strings. Update the README to say where the configuration now is and which tox it needs. No other file referred to `tox.ini`. Checked by comparing `tox config -e ALL` from `tox.ini` and from the new `pyproject.toml`, with both tox 4.22.0 and 4.67.1. For every environment, including `gix` and the packaging environments, the only differences are the names of the base tables and the config file path. Then, with the new configuration and each of those tox versions, `ruff`, `format`, `mypy`, `html`, `misc`, and `py39`, which installs and imports GitPython, ran and passed, and `tox -e py313 -- --collect-only -q test/test_util.py` passed its arguments to pytest, which collected 185 tests. `tox config -e gix` shows the default arguments, and arguments given after `--` replace them. The `misc` run includes the `check-toml` and `validate-pyproject` hooks, which pass on the new `pyproject.toml`. tox older than 4.21 does not read `[tool.tox]`, so it can no longer see `requires` and provision a newer tox, as it could with `tox.ini`. In a copy of the project, tox 4.11.3 and 4.20.0 both reported "No tox.ini or setup.cfg or pyproject.toml found, assuming empty tox.ini", and `tox -e ruff` failed with "provided environments not found in configuration file". tox 4.21.0 failed with "TypeError: 'tox>=4.22' is not of type 'Requirement'". tox 4.21.2 and 4.22.0 ran `ruff` and passed. Plain `tox`, with no `-e`, is worse: with tox 4.11.3, it ran an empty default environment and passed. That will be fixed separately, by giving older tox a `legacy_tox_ini` from which it can provision a newer tox. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 4b511bf commit 1b69c99

3 files changed

Lines changed: 113 additions & 79 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 [`./tox.ini`](https://github.com/gitpython-developers/GitPython/blob/main/tox.ini).
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.
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: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,115 @@ lint.unfixable = [
155155
"fuzzing/fuzz-targets/**" = [
156156
"E402", # environment setup must happen before the `git` module is imported, thus cannot happen at top of file
157157
]
158+
159+
[tool.tox]
160+
requires = ["tox>=4.22"]
161+
# Skip environments whose Python is not installed.
162+
skip_missing_interpreters = true
163+
env_list = [
164+
"py38",
165+
"py39",
166+
"py310",
167+
"py311",
168+
"py312",
169+
"py313",
170+
"py314",
171+
"py315",
172+
"ruff",
173+
"format",
174+
"mypy",
175+
"html",
176+
"misc",
177+
]
178+
179+
[tool.tox.env_run_base]
180+
description = "Run unit tests"
181+
package = "wheel"
182+
# Use the in-tree smmap and gitdb, as CI does, rather than releases from PyPI.
183+
deps = ["{tox_root}/smmap", "{tox_root}/gitdb"]
184+
extras = ["test"]
185+
pass_env = [
186+
"SSH_*",
187+
"GIT_PYTHON_GIT_EXECUTABLE",
188+
]
189+
set_env = { GIT_PYTHON_BACKEND = "cli" }
190+
commands = [["pytest", "--color=yes", { replace = "posargs", extend = true }]]
191+
192+
[tool.tox.env.py38]
193+
description = "Install and import GitPython (the tests need Python 3.11 or later)"
194+
extras = []
195+
commands = [
196+
["python", "-I", "-c", "import git; from git import _backend; assert _backend.name == 'cli'; print(git.__version__)"],
197+
]
198+
199+
[tool.tox.env.py39]
200+
description = "Install and import GitPython (the tests need Python 3.11 or later)"
201+
extras = []
202+
commands = [
203+
["python", "-I", "-c", "import git; from git import _backend; assert _backend.name == 'cli'; print(git.__version__)"],
204+
]
205+
206+
[tool.tox.env.py310]
207+
description = "Install and import GitPython (the tests need Python 3.11 or later)"
208+
extras = []
209+
commands = [
210+
["python", "-I", "-c", "import git; from git import _backend; assert _backend.name == 'cli'; print(git.__version__)"],
211+
]
212+
213+
[tool.tox.env.ruff]
214+
description = "Lint with Ruff"
215+
base_python = ["py39", "py310", "py311", "py312", "py313", "py314", "py315"]
216+
skip_install = true
217+
deps = ["ruff"]
218+
set_env = { CLICOLOR_FORCE = "1" } # Set NO_COLOR to override this.
219+
commands = [["ruff", "check", "."]]
220+
221+
[tool.tox.env.gix]
222+
set_env = { GIT_PYTHON_BACKEND = "gix" }
223+
description = "Run the suite with released GixPython and CLI fallback"
224+
base_python = ["python3"]
225+
package_env = ".pkg-gix"
226+
wheel_build_env = ".pkg-gix"
227+
extras = ["test", "gix"]
228+
# Let the tests use the package index, as pip is configured to, rather than disabling it.
229+
commands = [
230+
[
231+
"python",
232+
"test/run-local.py",
233+
"--allow-index",
234+
{ replace = "posargs", default = ["--backend-report=.cache/gix-coverage.json"], extend = true },
235+
],
236+
]
237+
238+
[tool.tox.env.format]
239+
description = "Check formatting with Ruff"
240+
base_python = ["py39", "py310", "py311", "py312", "py313", "py314", "py315"]
241+
skip_install = true
242+
deps = ["ruff"]
243+
set_env = { CLICOLOR_FORCE = "1" } # Set NO_COLOR to override this.
244+
commands = [["ruff", "format", "--check", "."]]
245+
246+
[tool.tox.env.mypy]
247+
description = "Typecheck with mypy"
248+
base_python = ["py39", "py310", "py311", "py312", "py313", "py314", "py315"]
249+
set_env = { MYPY_FORCE_COLOR = "1" }
250+
commands = [["mypy"]]
251+
252+
[tool.tox.env.html]
253+
description = "Build HTML documentation"
254+
base_python = ["py39", "py310", "py311", "py312", "py313", "py314", "py315"]
255+
extras = []
256+
dependency_groups = ["doc"]
257+
allowlist_externals = ["make"]
258+
commands = [
259+
["make", "BUILDDIR={env_tmp_dir}/doc/build", "-C", "doc", "clean"],
260+
["make", "BUILDDIR={env_tmp_dir}/doc/build", "-C", "doc", "html"],
261+
]
262+
263+
[tool.tox.env.misc]
264+
description = "Run other checks via pre-commit"
265+
base_python = ["py39", "py310", "py311", "py312", "py313", "py314", "py315"]
266+
skip_install = true
267+
deps = ["pre-commit"]
268+
set_env = { SKIP = "ruff-format,ruff-check" }
269+
commands = [["pre-commit", "run", "--all-files"]]

‎tox.ini‎

Lines changed: 0 additions & 78 deletions
This file was deleted.

0 commit comments

Comments
 (0)