🐛 fix(env): break circular dependency in environment_variables resolution#3816
Merged
gaborbernat merged 3 commits intotox-dev:mainfrom Feb 23, 2026
Merged
🐛 fix(env): break circular dependency in environment_variables resolution#3816gaborbernat merged 3 commits intotox-dev:mainfrom
gaborbernat merged 3 commits intotox-dev:mainfrom
Conversation
set_env substitutions like {env_site_packages_dir} trigger virtualenv
session creation which re-enters environment_variables, causing a
RecursionError silently caught as RuntimeError. Add a re-entrancy guard
that returns pass_env + PATH without set_env on recursive calls.
Also fix tests asserting VirtualEnvOptions.copies which is only present
when the creator's meta reports can_copy (not all platforms).
for more information, see https://pre-commit.ci
set_env substitutions like {env_site_packages_dir} trigger virtualenv
session creation which re-enters environment_variables, causing a
RecursionError silently caught as RuntimeError. Add a re-entrancy guard
that returns pass_env + PATH without set_env on recursive calls.
Also fix tests asserting VirtualEnvOptions.copies which is only present
when the creator's meta reports can_copy (not all platforms).
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
set_envcontains substitutions referencing{env_site_packages_dir},{env_bin_dir}, or similar lazy constants, resolving them triggers virtualenv session creation. The session creation callsvirtualenv_env_vars()which callsself.environment_variables, re-entering the property that's already mid-resolution. This causes aRecursionErrorwhich, being a subclass ofRuntimeError, gets silently caught by_get_python-- making tox report "could not find python interpreter" when the interpreter is perfectly findable.🔧 The fix adds a re-entrancy guard (
_resolving_env_varsflag) toToxEnv.environment_variables. When a recursive call is detected duringset_envloading or key resolution, it returnspass_env + PATHwithoutset_envvalues. This is sufficient for virtualenv's discovery and session creation, and the fullset_envresolution completes normally once the session exists. The guard preserves fullset_envsupport -- values set viaset_envintox.tomlstill work correctly forVIRTUALENV_*variables.Additionally fixes
test_virtualenv_apitests that unconditionally assertVirtualEnvOptions.copies, which is only present when the creator's meta reportscan_copy. On platforms like macOS with Homebrew CPython,--copiesis never added to argparse so the attribute doesn't exist.