Skip to content

Commit

Permalink
Split tox "lint" env into three envs, all safe
Browse files Browse the repository at this point in the history
It makes sense for ruff linting and ruff autoformatting to be
easily runnable individually and to have their results be shown
separately. Splitting them out in tox.ini also makes it so tox can
do the other tests corresponding to those in lint.yml on CI in an
environment that requries no custom behavior from pre-commit other
than skipping the ruff checks.

The ruff linting ("ruff") and ruff format checking ("format") tox
environments specify ruff as a dependency and call it directly
rather than through pre-commit, invoking it in such a way that it
does not attempt to modify any files in the working tree.

See b059cd5 (gitpython-developers#1868) for context. All three of these tox envs that
"lint" has been split into are listed in the env_list and thus run
automatically when tox is run with no arguments, since no tox envs
unexpectedly (or at all) modify files in the working tree anymore.

One limitation of the current approach is that new pre-commit hooks
configured in .pre-commit-config.yml will automatically be run as
part of the "misc" tox environment, which means that new unexpected
mutating operatons could be added if the impact on tox is not
considered. The benefit of having it work this way is that most
hooks that are likely to be added to GitPython would not modify
files and would be wanted as part of "misc". But this may benefit
from further refinement.
  • Loading branch information
EliahKagan committed Mar 13, 2024
1 parent a7db39a commit 45dede1
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
requires = tox>=4
env_list = py{37,38,39,310,311,312}, mypy, html
env_list = py{37,38,39,310,311,312}, ruff, format, mypy, html, misc

[testenv]
description = Run unit tests
Expand All @@ -9,10 +9,17 @@ extras = test
pass_env = SSH_*
commands = pytest --color=yes {posargs}

[testenv:lint]
description = Lint via pre-commit
[testenv:ruff]
description = Lint with Ruff
base_python = py{39,310,311,312,38,37}
commands = pre-commit run --all-files
deps = ruff
commands = ruff check .

[testenv:format]
description = Check formatting with Ruff
base_python = py{39,310,311,312,38,37}
deps = ruff
commands = ruff format --check .

[testenv:mypy]
description = Typecheck with mypy
Expand All @@ -28,3 +35,10 @@ allowlist_externals = make
commands =
make BUILDDIR={env_tmp_dir}/doc/build -C doc clean
make BUILDDIR={env_tmp_dir}/doc/build -C doc html

[testenv:misc]
description = Run other checks via pre-commit
base_python = py{39,310,311,312,38,37}
set_env =
SKIP = ruff-format,ruff
commands = pre-commit run --all-files

0 comments on commit 45dede1

Please sign in to comment.