gh-156404: Restore the 'fullname' variable for .pth import lines - #156406
Conversation
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
warsaw
left a comment
There was a problem hiding this comment.
Thanks for the report and the fix!
|
Thanks @arcivanov for the PR, and @warsaw for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15. |
|
GH-156431 is a backport of this pull request to the 3.15 branch. |
|
|
|
PEP 829 moved
.pthhandling out ofsite.addpackage()and intosite.StartupState._exec_imports().importlines in.pthfiles are stillexec()'d there, but the local variable holding the path of the.pthfile being processed was renamed fromfullnametofilenamein the move, so.pthfiles generated before 3.15 that readfullnamenow raiseNameErroron every interpreter startup:This is the same class of regression as gh-149671, which was fixed in f7ab7c4 by injecting the
sitedirlocal for compatibility with the-nspkg.pthfiles generated by setuptools. This change givesfullnameidentical treatment, immediately below that existing shim.PEP 829 keeps executing
.pthimportlines 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. Bothfullnameandfilenameare bound after this change, so.pthfiles written for either naming work.Real-world impact: every wheel built by
wheel-axlebefore 0.0.13 installs a.pthcontainingimport wheel_axle.runtime; wheel_axle.runtime.finalize(fullname);, and such wheels are already published. The interpreter still starts, becausesiteprints 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.pthis never consumed. Downstream tracking issue: karellen/wheel-axle#38Adds
test_fullname_variablealongside the existingtest_sitedir_variable. Verified with--with-pydebugon both branches: the new test fails with theNameErrorabove before the change and passes after it.test_site/test_venvare green onmain(run=149 skipped=16) and on3.15atv3.15.0rc1-86-gd0484ab51a7(run=139 skipped=15).3.15is affected identically and needsneeds backport to 3.15.