Skip to content

Comments

🐛 fix(config): env variable substitution in package envs#3746

Merged
gaborbernat merged 2 commits intotox-dev:mainfrom
gaborbernat:fix-envtmpdir-expansion-regression-3238
Feb 18, 2026
Merged

🐛 fix(config): env variable substitution in package envs#3746
gaborbernat merged 2 commits intotox-dev:mainfrom
gaborbernat:fix-envtmpdir-expansion-regression-3238

Conversation

@gaborbernat
Copy link
Member

@gaborbernat gaborbernat commented Feb 18, 2026

Since tox 4.14.1, substitutions like {envtmpdir} and {env_tmp_dir} stopped expanding in external package environment commands and package_glob. 🐛 This affected users with package = external configurations, where build commands containing path substitutions would receive literal {envtmpdir} strings instead of actual paths, breaking their package builds.

The root cause is in Config.get_env(). When a package environment is first created with package=True, it gets cached in _key_to_conf_set with a base-dependent key (e.g., env_pkg_base). Later, during substitution resolution, the replacement code calls get_env() with the default package=False, producing a different cache key (e.g., env_run_base). This creates a duplicate EnvConfigSet without the registered config definitions, so lookups for env_tmp_dir fail silently and the substitution is left unexpanded. The fix adds a secondary index keyed solely by environment name, ensuring get_env() returns the existing config set regardless of the package flag.

This also fixes an inverted condition in clear_env() that was keeping matching entries instead of removing them. ⚠️ The clear_env bug had no user-visible effect because the method is only called during env re-creation where the entire dict gets rebuilt, but it's corrected here for correctness.

Fixes #3238

When get_env() was called during substitution resolution with
package=False for an env already created with package=True, a
duplicate config set was created due to differing cache keys.
Add a secondary index keyed by env name to return existing config
sets regardless of the package flag.

Also fix inverted condition in clear_env that kept matching entries
instead of removing them.

Fixes tox-dev#3238
@gaborbernat gaborbernat added bug:normal affects many people or has quite an impact area:configuration labels Feb 18, 2026
@gaborbernat gaborbernat enabled auto-merge (squash) February 18, 2026 04:31
@gaborbernat gaborbernat merged commit d01bfe4 into tox-dev:main Feb 18, 2026
28 checks passed
@gaborbernat gaborbernat deleted the fix-envtmpdir-expansion-regression-3238 branch February 18, 2026 07:29
@Luthaf
Copy link

Luthaf commented Feb 18, 2026

Many thanks, I can confirm this fixes the issue for all my packages!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:configuration bot:chronographer:provided bug:normal affects many people or has quite an impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tox v4.14.1 is no longer expanding {envtmpdir} (and potentially other variables)

2 participants