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
6 changes: 6 additions & 0 deletions Lib/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,12 @@ def _exec_imports(self):
# generated by setuptools use: sys._getframe(1).f_locals['sitedir'].
sitedir = os.path.dirname(filename)

# Inject 'fullname' local variable in the current frame for
# compatibility with Python 3.14, where the path of the ".pth"
# file being processed was available to import lines under that
# name.
fullname = filename

# Given "/path/to/foo.pth", check whether "/path/to/foo.start" was
# registered in this same batch.
name, dot, pth = filename.rpartition(".")
Expand Down
17 changes: 17 additions & 0 deletions Lib/test/test_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,23 @@ def test_sitedir_variable(self):
sitedir = stdout.getvalue().rstrip()
self.assertEqual(sitedir, pth_dir)

def test_fullname_variable(self):
# gh-156404: ".pth" files generated before Python 3.15 read the path
# of the file being processed from the frame executing the import
# line, under the name "fullname". For example, "wheel-axle"
# generates: "import wheel_axle.runtime;
# wheel_axle.runtime.finalize(fullname);"
code = '; '.join((
"import sys",
"print(fullname)",
"print(filename)",
))
pth_dir, pth_fn = self.make_pth(code)
with support.captured_stdout() as stdout:
site.addpackage(pth_dir, pth_fn, set())
expected = os.path.join(pth_dir, pth_fn)
self.assertEqual(stdout.getvalue().splitlines(), [expected, expected])

# This tests _getuserbase, hence the double underline
# to distinguish from a test for getuserbase
def test__getuserbase(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Restore compatibility with :file:`.pth` files generated before Python 3.15 in
the :mod:`site` module. Inject the ``fullname`` variable in the frame which
executes pth code.
Loading