gh-149819: Fix .pth files not loaded in Python subprocesses#149888
Open
IntentBug wants to merge 1 commit into
Open
gh-149819: Fix .pth files not loaded in Python subprocesses#149888IntentBug wants to merge 1 commit into
IntentBug wants to merge 1 commit into
Conversation
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
After PR pythongh-149583 (Fix double evaluation of .pth and .site files in venvs), .pth files are no longer loaded in subprocesses started with subprocess.run([sys.executable, ...]). The root cause: main() seeds known_paths from removeduppaths() with all sys.path entries inherited from the parent process. addsitedir() then skips .pth processing for every directory already in known_paths. Fix: - main(): call removeduppaths() for dedup but start known_paths as a fresh empty set, so that addsitedir() processes .pth files in every site-packages directory regardless of inherited sys.path. - addsitedir(): move known_paths.add() before the sys.path.append and guard the append with 'sitedir not in sys.path' to avoid creating duplicate entries when called with a fresh known_paths. This preserves the pythongh-75723 dedup guarantee while allowing subprocesses to load .pth files.
3b83675 to
b7f6ba1
Compare
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.
After PR gh-149583 (Fix double evaluation of .pth and .site files in venvs), .pth files are no longer loaded in subprocesses started with subprocess.run([sys.executable, ...]).
Root cause:
main()seedsknown_pathsfromremoveduppaths()with all sys.path entries inherited from the parent process.addsitedir()then skips .pth processing for every directory already in known_paths.Fix (2 changes in Lib/site.py, +10/−6 lines):
main(): callremoveduppaths()for dedup but startknown_pathsas a fresh empty setaddsitedir(): guardsys.path.appendwithsitedir not in sys.pathto avoid duplicates when called with fresh known_pathsVerification:
./python -m test test_site: 90/90 tests pass (0 failures, 6 skipped)Closes gh-149819