@@ -254,7 +254,6 @@ class StartupState:
254254 '_path_entries' ,
255255 '_importexecs' ,
256256 '_entrypoints' ,
257- '_sitedir' ,
258257 )
259258
260259 def __init__ (self , known_paths = None ):
@@ -287,7 +286,6 @@ def __init__(self, known_paths=None):
287286 # when an entry fails.
288287 self ._importexecs = {}
289288 self ._entrypoints = {}
290- self ._sitedir = None
291289
292290 def addsitedir (self , sitedir ):
293291 """Add a site directory and accumulate its .pth and .start startup data.
@@ -399,7 +397,6 @@ def _read_pth_file(self, sitedir, name):
399397 accepted paths are added to it so that subsequent .pth files in
400398 the same batch don't add them more than once.
401399 """
402- self ._sitedir = sitedir
403400
404401 lines , filename = _read_pthstart_file (sitedir , name , ".pth" )
405402 if lines is None :
@@ -504,16 +501,16 @@ def _extend_syspath(self):
504501 )
505502
506503 def _exec_imports (self ):
507- # Inject 'sitedir' local variable in the current frame for
508- # compatibility with Python 3.14. Especially, "-nspkg.pth" files
509- # generated by setuptools use: sys._getframe(1).f_locals['sitedir'].
510- sitedir = self ._sitedir
511-
512504 # For each `import` line we've seen in a .pth file, exec() it in
513505 # order, unless the .pth has a matching .start file in this same
514506 # batch. In that case, PEP 829 says the import lines are
515507 # suppressed in favor of the .start's entry points.
516508 for filename , imports in self ._importexecs .items ():
509+ # Inject 'sitedir' local variable in the current frame for
510+ # compatibility with Python 3.14. Especially, "-nspkg.pth" files
511+ # generated by setuptools use: sys._getframe(1).f_locals['sitedir'].
512+ sitedir = os .path .dirname (filename )
513+
517514 # Given "/path/to/foo.pth", check whether "/path/to/foo.start" was
518515 # registered in this same batch.
519516 name , dot , pth = filename .rpartition ("." )
0 commit comments