# batch. In that case, PEP 829 says the import lines are
# suppressed in favor of the .start's entry points.
for filename, imports in self._importexecs.items():
+ # Inject 'sitedir' local variable in the current frame for
+ # compatibility with Python 3.14. Especially, "-nspkg.pth" files
+ # generated by setuptools use: sys._getframe(1).f_locals['sitedir'].
+ sitedir = os.path.dirname(filename)
+
# Given "/path/to/foo.pth", check whether "/path/to/foo.start" was
# registered in this same batch.
name, dot, pth = filename.rpartition(".")
self.assertNotIn(site.makepath(pth_file.good_dir_path)[0], sys.path)
self.assertIn(pth_file.base_dir, sys.path)
+ def test_sitedir_variable(self):
+ # gh-149671: setuptools use of `-nspkg.pth` files in Python < 3.15.
+ code = '; '.join((
+ # Code used by "-nspkg.pth" files generated by setuptools.
+ "import sys",
+ "sitedir = sys._getframe(1).f_locals['sitedir']",
+ "print(sitedir)",
+ ))
+ pth_dir, pth_fn = self.make_pth(code)
+ with support.captured_stdout() as stdout:
+ known_paths = site.addpackage(pth_dir, pth_fn, set())
+ sitedir = stdout.getvalue().rstrip()
+ self.assertEqual(sitedir, pth_dir)
+
# This tests _getuserbase, hence the double underline
# to distinguish from a test for getuserbase
def test__getuserbase(self):