Thanks to visit codestin.com
Credit goes to github.com

Skip to content

🐛 fix(pip): invalidate install cache on resolution env var changes#3921

Merged
rahuldevikar merged 7 commits into
tox-dev:mainfrom
gaborbernat:fix/3917-install-cache-env-vars
Apr 9, 2026
Merged

🐛 fix(pip): invalidate install cache on resolution env var changes#3921
rahuldevikar merged 7 commits into
tox-dev:mainfrom
gaborbernat:fix/3917-install-cache-env-vars

Conversation

@gaborbernat
Copy link
Copy Markdown
Member

@gaborbernat gaborbernat commented Apr 9, 2026

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 where UV_EXCLUDE_NEWER in setenv was ignored after the first run (tox-uv side: tox-dev/tox-uv#325).

The fix adds an overridable _install_env_vars() method to Pip that returns a filtered dict of known resolution-affecting PIP_* variables from the resolved environment. This dict is folded into the cache key for both the deps-style and list-of-deps install paths. Only vars that genuinely affect which versions get selected are included; cosmetic ones like PIP_TIMEOUT or PIP_VERBOSE are 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_deps cache format changes from a bare list to a dict; old-format caches are handled gracefully by treating a non-dict old value as the requirements list directly.

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
@gaborbernat gaborbernat added the bug:normal affects many people or has quite an impact label Apr 9, 2026
@rahuldevikar rahuldevikar merged commit d15c8fa into tox-dev:main Apr 9, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

2 participants