Repository navigation
🐛 fix(seed): make seed images read-only - #3757
Merged
gaborbernat merged 1 commit intoNov 21, 2026
Merged
Conversation
With --symlink-app-data an environment links into the cached seed image. pip install --ignore-installed skips the uninstall that would remove those links, so pip wrote through them and changed the package for every environment sharing the image. Close the image's directories as well as its files, so that write fails instead. Bytecode caches stay open because interpreters compile into them on load, and the image root stays open so a build can still move it into place. Deleting the cache goes through a separate helper that reopens the directories first, while safe_delete keeps refusing a read-only directory. Windows directories stay as they are: closing one does not stop new files there and blocks deleting it. The permissions do not bind root. Fixes pypa#3620
gaborbernat
marked this pull request as ready for review
November 21, 2026 18:15
gaborbernat
enabled auto-merge (squash)
November 21, 2026 18:15
gaborbernat
marked this pull request as draft
November 21, 2026 18:25
auto-merge was automatically disabled
November 21, 2026 18:25
Pull request was converted to draft
gaborbernat
marked this pull request as ready for review
November 21, 2026 18:57
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.
With
--symlink-app-data, every environment links to one cached copy of each seed package (pip, and setuptools where virtualenv seeds it), which virtualenv calls a seed image and keeps in its app-data cache directory. Runningpip install --ignore-installed pipin one of them rewrote that shared image, and pip could stop working in another environment that had installed nothing (#3620). 🔒 That command now fails with a permission error, and the shared image and the other environments stay as they were.Upgrades,
--force-reinstalland uninstalls were never affected: pip removes the environment's links first and then installs a private copy.--ignore-installedskips that uninstall step, so the links were still in place when pip wrote its files.Design
The seed image cache is now read-only once an image is built: its files on every platform, and its directories on POSIX, where replacing a file needs write permission on the directory that holds it. Two parts stay writable. Bytecode cache directories do, because interpreters compile into them when they load a module; pip fails on its first source file, before it compiles anything. The top directory of an image does, so a finished build can still be moved into place; environments link to the directories below it, never to the top directory itself.
The code that manages the cache restores write permission before it deletes: on
--reset-app-data, for temporary app-data and when it rebuilds an image. Everything else virtualenv deletes, such as an environment being cleared, still refuses a read-only directory. Copy seeding writes new files with fixed permissions instead of copying them from the image, so copied seed packages stay writable.The trade-off is that
--ignore-installedfails where a private copy would be nicer. Giving each environment its own files is what #3755 does, and it reports creation of a linked environment going from 3.6 ms to 15 ms. This change adds one pass over an image when it is built, and no work when an environment is created.Behavior changes
--symlink-app-dataenvironment,pip install --ignore-installedof a seed package fails withPermission denied. Use--force-reinstallto get a private copy.root, sorootcan still change the shared image this way.rm -rfnow fails on POSIX. Use--reset-app-data, or runchmod -R u+won it first.--reset-app-datarebuilds them; environments linked to the old images must then be recreated, which a reset already required.Supersedes #3755.
Fixes #3620