Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions Lib/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,13 +490,16 @@ def addsitedir(sitedir, known_paths=None, *, defer_processing_start_files=False)
reset = False
sitedir, sitedircase = makepath(sitedir)

# If the normcase'd new sitedir isn't already known, append it to
# sys.path, keep a record of it, and process all .pth and .start files
# found in that directory. If the new sitedir is known, be sure not
# to process all of those more than once! gh-75723
# If the normcase'd new sitedir isn't already known, record it to
# prevent re-processing, append it to sys.path (only if not already
# present), and process all .pth and .start files found in that
# directory. Use a direct sys.path membership check for the append
# guard so that callers (like main()) can pass a fresh known_paths
# set while avoiding duplicate sys.path entries (gh-149819).
if sitedircase not in known_paths:
sys.path.append(sitedir)
known_paths.add(sitedircase)
if sitedir not in sys.path:
sys.path.append(sitedir)

try:
names = os.listdir(sitedir)
Expand Down Expand Up @@ -1000,7 +1003,8 @@ def main():
global ENABLE_USER_SITE

orig_path = sys.path[:]
known_paths = removeduppaths()
removeduppaths()
known_paths = set()
if orig_path != sys.path:
# removeduppaths() might make sys.path absolute.
# Fix __file__ of already imported modules too.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Fix regression in :func:`site.addsitedir` where ``.pth`` files were no
longer processed in Python subprocesses. This happened because
:func:`site.main` seeded ``known_paths`` with entries inherited from
the parent process, causing ``addsitedir`` to skip ``.pth`` processing.