Title: [3.15] gh-149819: fix .pth and .start file processing in subprocess when inheriting PYTHONPATH (GH-150177) by miss-islington · Pull Request #150202 · python/cpython · GitHub
Open Graph Title: [3.15] gh-149819: fix .pth and .start file processing in subprocess when inheriting PYTHONPATH (GH-150177) by miss-islington · Pull Request #150202 · python/cpython
X Title: [3.15] gh-149819: fix .pth and .start file processing in subprocess when inheriting PYTHONPATH (GH-150177) by miss-islington · Pull Request #150202 · python/cpython
Description: gh-149819: Fix .pth files not loaded in Python subprocesses 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, ...]). 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 gh-75723 dedup guarantee while allowing subprocesses to load .pth files. Fill out the tests for GH#149888 Extend _make_start() and _make_pth() to take an optional basedir which is used instead of site.tmpdir if given. Add test_pth_processed_when_sitedir_already_on_path() to test the core GH#149819 bug: .pth files in subprocesses aren't handled if PYTHONPATH pointing to the .pth directory is inherited. Similarly add test_start_processed_when_sitedir_already_on_path() to verify that .start files in the same circumstances are also now processed. Update Lib/site.py Co-authored-by: scoder stefan_ml@behnel.de Oops! Remove redundant code (cherry picked from commit 3c298e2) Co-authored-by: Barry Warsaw barry@python.org Co-authored-by: BugBounty Mind bugbounty-mind@deepseek.tui Co-authored-by: scoder stefan_ml@behnel.de
Open Graph Description: gh-149819: Fix .pth files not loaded in Python subprocesses After PR gh-149583 (Fix double evaluation of .pth and .site files in venvs), .pth files are no longer loaded in subprocesses started wit...
X Description: gh-149819: Fix .pth files not loaded in Python subprocesses After PR gh-149583 (Fix double evaluation of .pth and .site files in venvs), .pth files are no longer loaded in subprocesses started wit...
Opengraph URL: https://github.com/python/cpython/pull/150202
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:cd399d71-1be6-23de-e8ee-96fc62803a55 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 9C60:3C94F8:F20572:153C83A:6A566F45 |
| html-safe-nonce | f73615402b3c2aec7f39b94cd27710fbac0d32a5a5f79e27b62083db9237c4f8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5QzYwOjNDOTRGODpGMjA1NzI6MTUzQzgzQTo2QTU2NkY0NSIsInZpc2l0b3JfaWQiOiI2NDgzNzY3ODc4MzM2NTQwNDg1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 30270891e74860078532d3b49f4d62f816e37a4c596f50ae7f6eb08a6a277b22 |
| hovercard-subject-tag | pull_request:3726497413 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python/cpython/pull/150202/files |
| twitter:image | https://avatars.githubusercontent.com/u/31488909?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/31488909?s=400&v=4 |
| og:image:alt | gh-149819: Fix .pth files not loaded in Python subprocesses After PR gh-149583 (Fix double evaluation of .pth and .site files in venvs), .pth files are no longer loaded in subprocesses started wit... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 19b5ee9431dcfce15ab4b001d626e4e3a6ba1acb7be814813a52bbebd9a86ef5 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | afc01ffdb045f4ff81c6122091366ade7b6166b7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width