Skip to content

✨ feat(env): add recreate_commands config key#3793

Merged
gaborbernat merged 1 commit intotox-dev:mainfrom
gaborbernat:feature/external-cache-control
Feb 20, 2026
Merged

✨ feat(env): add recreate_commands config key#3793
gaborbernat merged 1 commit intotox-dev:mainfrom
gaborbernat:feature/external-cache-control

Conversation

@gaborbernat
Copy link
Copy Markdown
Member

When tox run -r recreates 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_commands is a new list[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 clean work naturally. The env's bin directory is temporarily added to the allowlist so command resolution works correctly even though _setup_env hasn't run yet in the current session.

Failures in recreate_commands are 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

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
@gaborbernat gaborbernat force-pushed the feature/external-cache-control branch from 4c7a702 to b8b1058 Compare February 20, 2026 04:45
@gaborbernat gaborbernat merged commit ae36881 into tox-dev:main Feb 20, 2026
28 checks passed
@gaborbernat gaborbernat deleted the feature/external-cache-control branch February 20, 2026 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support external cache control commands

1 participant