✨ feat(env): add recreate_commands config key#3793
Merged
gaborbernat merged 1 commit intotox-dev:mainfrom Feb 20, 2026
Merged
Conversation
When tox recreates an environment (`-r`), tools like pre-commit maintain external caches that survive the environment directory wipe. Users had no way to clean those caches as part of the recreation lifecycle. recreate_commands runs inside the still-existing environment before its directory is removed, so installed tools remain available. Failures are logged as warnings and never block recreation since the environment is being destroyed anyway. The env's bin directory is temporarily added to the allowlist so commands resolve correctly before setup runs. Closes tox-dev#3423
4c7a702 to
b8b1058
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When
tox run -rrecreates an environment, external caches managed by tools inside that environment (e.g. pre-commit) survive the directory wipe. Users had no mechanism to clean those caches as part of the recreation lifecycle, leading to stale state that defeats the purpose of recreation.🧹
recreate_commandsis a newlist[Command]config key that runs inside the still-existing environment before its directory is removed. This placement is deliberate -- the old virtualenv and its installed tools remain available, so commands like{env_python} -Im pre_commit cleanwork naturally. The env's bin directory is temporarily added to the allowlist so command resolution works correctly even though_setup_envhasn't run yet in the current session.Failures in
recreate_commandsare logged as warnings but never block recreation -- the environment is being destroyed anyway, so a cleanup failure shouldn't prevent a fresh start. The commands are skipped entirely on first creation (no env directory exists yet) and on normal re-runs without-r.Closes #3423