🐛 fix(pip): invalidate install cache on resolution env var changes#3921
Merged
rahuldevikar merged 7 commits intoApr 9, 2026
Merged
Conversation
When a user changes a resolution-affecting env var via setenv (e.g. PIP_INDEX_URL), tox previously skipped reinstalling because the requirements list was unchanged. The cache key only tracked options, requirements, constraints, and constraint_options — not the environment variables that control where or how packages are resolved. Adds _install_env_vars() to Pip, returning a filtered dict of known resolution-affecting PIP_* vars from the resolved environment. This dict is included in both the _install_requirement_file and _install_list_of_deps cache keys. Subclasses (e.g. tox-uv's UvInstaller) can override this method to include their own installer-specific vars. Not all PIP_* vars are included — only those that affect which package versions get selected (index, find-links, pre-release, constraints, require-hashes, trusted-host). Cosmetic and performance vars like PIP_TIMEOUT or PIP_VERBOSE are excluded to avoid spurious reinstalls. Fixes tox-dev#3917
for more information, see https://pre-commit.ci
…esolution vars" This reverts commit 35f1f8d.
rahuldevikar
approved these changes
Apr 9, 2026
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.
Setting a resolution-affecting env var via
set_env(e.g.PIP_INDEX_URL,PIP_EXTRA_INDEX_URL) had no effect on an already-cached tox environment. The install cache key tracked requirements, constraints, install options, and constraint options — but not the environment variables that control where or how pip resolves packages. A user who switched index URLs between runs would silently get stale packages from the previous cache. Reported in #3917, originally surfaced through tox-uv whereUV_EXCLUDE_NEWERinsetenvwas ignored after the first run (tox-uv side: tox-dev/tox-uv#325).The fix adds an overridable
_install_env_vars()method toPipthat returns a filtered dict of known resolution-affectingPIP_*variables from the resolved environment. This dict is folded into the cache key for both thedeps-style and list-of-deps install paths. Only vars that genuinely affect which versions get selected are included; cosmetic ones likePIP_TIMEOUTorPIP_VERBOSEare excluded to avoid spurious reinstalls. 🐛 The method is intentionally overridable so that installer plugins (e.g. tox-uv) can extend it with their own resolution-affecting vars.On the first run after upgrading, existing environments will see a one-time reinstall as the cache gains the new
"env"key. The_install_list_of_depscache format changes from a bare list to a dict; old-format caches are handled gracefully by treating a non-dictoldvalue as the requirements list directly.