🐛 fix(config): defer TOML set_env string substitution#3759
Merged
Conversation
The TOML loader eagerly resolved all substitutions in set_env values
via Unroll before constructing SetEnv. When set_env contained
references like {env_site_packages_dir}, this triggered a circular
dependency: set_env → env_site_packages_dir → create_python_env →
system_site_packages → environment_variables → set_env.
The INI loader already handles this by deferring string substitution
for SetEnv values. Apply the same pattern to the TOML loader: resolve
structural TOML constructs (refs, posargs, env lookups) but skip
string-level substitution, providing a real replacer for lazy
per-value resolution.
Closes tox-dev#3758
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.
Using substitutions like
{env_site_packages_dir}insideset_envin TOML format causes aRecursionErrorbecause the TOML loader eagerly resolves all string substitutions viaUnrollbefore constructingSetEnv. This creates a circular dependency:set_env→env_site_packages_dir→create_python_env()→system_site_packages→environment_variables→set_env.The INI loader already handles this correctly by detecting
SetEnvtype and deferring string substitution — raw strings are stored as-is and only resolved when individual env vars are accessed viaSetEnv.load(). 🔧 This applies the same pattern to the TOML loader: structural TOML constructs (replace: ref,replace: posargs,replace: env) are still resolved during config loading, but string-level{...}substitutions are deferred via a proper TOML-aware replacer passed toSetEnv.use_replacer().Discovered via pypa/virtualenv#3050 when migrating virtualenv's config from
tox.initotox.toml. The same configuration that worked in INI format caused infinite recursion in TOML because of the eager substitution.Closes #3758