Skip to content

gh-156404: Restore the 'fullname' variable for .pth import lines - #156406

Open
arcivanov wants to merge 1 commit into
python:mainfrom
arcivanov:gh-156404-pth-fullname
Open

gh-156404: Restore the 'fullname' variable for .pth import lines#156406
arcivanov wants to merge 1 commit into
python:mainfrom
arcivanov:gh-156404-pth-fullname

Conversation

@arcivanov

@arcivanov arcivanov commented Aug 26, 2026

Copy link
Copy Markdown

PEP 829 moved .pth handling out of site.addpackage() and into site.StartupState._exec_imports(). import lines in .pth files are still exec()'d there, but the local variable holding the path of the .pth file being processed was renamed from fullname to filename in the move, so .pth files generated before 3.15 that read fullname now raise NameError on every interpreter startup:

Error in import line from /tmp/tmp3kbbbxtg/foo.pth: import sys; print(fullname)
  Traceback (most recent call last):
    File "Lib/site.py", line 533, in _exec_imports
      exec(line)
      ~~~~^^^^^^
    File "<string>", line 1, in <module>
  NameError: name 'fullname' is not defined. Did you mean: 'filename'?

This is the same class of regression as gh-149671, which was fixed in f7ab7c4 by injecting the sitedir local for compatibility with the -nspkg.pth files generated by setuptools. This change gives fullname identical treatment, immediately below that existing shim.

PEP 829 keeps executing .pth import lines through 3.17, so the old mechanism has not been retired; the lines still run, they just run against a frame that no longer exposes the name they were written against. Both fullname and filename are bound after this change, so .pth files written for either naming work.

Real-world impact: every wheel built by wheel-axle before 0.0.13 installs a .pth containing import wheel_axle.runtime; wheel_axle.runtime.finalize(fullname);, and such wheels are already published. The interpreter still starts, because site prints the traceback and continues, but the post-install hook never runs, so the symlinks the wheel declares are never created, and the error repeats on every startup because the .pth is never consumed. Downstream tracking issue: karellen/wheel-axle#38

Adds test_fullname_variable alongside the existing test_sitedir_variable. Verified with --with-pydebug on both branches: the new test fails with the NameError above before the change and passes after it. test_site/test_venv are green on main (run=149 skipped=16) and on 3.15 at v3.15.0rc1-86-gd0484ab51a7 (run=139 skipped=15).

3.15 is affected identically and needs needs backport to 3.15.

PEP 829 moved .pth handling from site.addpackage() into
StartupState._exec_imports(), and the local holding the path of the
.pth file being processed was renamed from 'fullname' to 'filename'.
Import lines in .pth files generated before Python 3.15 read that
local, so they now fail with NameError on every interpreter startup.

Inject 'fullname' into the frame which executes pth code, next to the
'sitedir' shim added for pythongh-149671.

Reported downstream as karellen/wheel-axle#38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant