From 7d06a0af1720e1962b324d8abf5865121ca492bc Mon Sep 17 00:00:00 2001 From: Steve Dower Date: Tue, 19 Aug 2025 21:28:28 +0100 Subject: [PATCH 1/2] gh-120037: Disable user site packages when a ._pth file is used (GH-137428) --- Doc/c-api/init_config.rst | 7 +++++++ Lib/test/test_site.py | 9 +++++++++ .../2025-08-05-20-24-12.gh-issue-120037.MB7MmI.rst | 2 ++ Modules/getpath.py | 1 + 4 files changed, 19 insertions(+) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2025-08-05-20-24-12.gh-issue-120037.MB7MmI.rst diff --git a/Doc/c-api/init_config.rst b/Doc/c-api/init_config.rst index 24be9ead3874d1..4f0199838e151d 100644 --- a/Doc/c-api/init_config.rst +++ b/Doc/c-api/init_config.rst @@ -2258,6 +2258,7 @@ If a ``._pth`` file is present: * Set :c:member:`~PyConfig.isolated` to ``1``. * Set :c:member:`~PyConfig.use_environment` to ``0``. * Set :c:member:`~PyConfig.site_import` to ``0``. +* Set :c:member:`~PyConfig.user_site_directory` to ``0`` (since 3.15). * Set :c:member:`~PyConfig.safe_path` to ``1``. If :c:member:`~PyConfig.home` is not set and a ``pyvenv.cfg`` file is present in @@ -2278,6 +2279,12 @@ The ``__PYVENV_LAUNCHER__`` environment variable is used to set therefore affected by :option:`-S`. +.. versionchanged:: 3.15 + + :c:member:`~PyConfig.user_site_directory` is now set to ``0`` when a + ``._pth`` file is present. + + Py_GetArgcArgv() ================ diff --git a/Lib/test/test_site.py b/Lib/test/test_site.py index 39c451fbbbba41..32fcf3162e8efd 100644 --- a/Lib/test/test_site.py +++ b/Lib/test/test_site.py @@ -804,6 +804,15 @@ def test_underpth_dll_file(self): )], env=env) self.assertTrue(rc, "sys.path is incorrect") + @support.requires_subprocess() + def test_underpth_no_user_site(self): + pth_lines = [test.support.STDLIB_DIR, 'import site'] + exe_file = self._create_underpth_exe(pth_lines) + p = subprocess.run([exe_file, '-X', 'utf8', '-c', + 'import sys; ' + 'sys.exit(not sys.flags.no_user_site)']) + self.assertEqual(p.returncode, 0, "sys.flags.no_user_site was 0") + class CommandLineTests(unittest.TestCase): def exists(self, path): diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-08-05-20-24-12.gh-issue-120037.MB7MmI.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-08-05-20-24-12.gh-issue-120037.MB7MmI.rst new file mode 100644 index 00000000000000..15b8b8f3648ac6 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2025-08-05-20-24-12.gh-issue-120037.MB7MmI.rst @@ -0,0 +1,2 @@ +Disable user site packages directory when a ``._pth`` file is used, even if +it contains ``import site``. diff --git a/Modules/getpath.py b/Modules/getpath.py index b89d7427e3febd..ceb605a75c85f4 100644 --- a/Modules/getpath.py +++ b/Modules/getpath.py @@ -790,6 +790,7 @@ def search_up(prefix, *landmarks, test=isfile): config['isolated'] = 1 config['use_environment'] = 0 config['site_import'] = 0 + config['user_site_directory'] = 0 config['safe_path'] = 1 pythonpath = [] for line in pth: From d22a7456443415961b93169b851ab7e550be8791 Mon Sep 17 00:00:00 2001 From: Itamar Oren Date: Tue, 19 Aug 2025 14:30:59 -0700 Subject: [PATCH 2/2] gh-137964: Remove the "experimental" designation from the Windows installer (GH-137965) --- Tools/msi/bundle/Default.wxl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tools/msi/bundle/Default.wxl b/Tools/msi/bundle/Default.wxl index 0bd3644b58b747..335c1d922d97b5 100644 --- a/Tools/msi/bundle/Default.wxl +++ b/Tools/msi/bundle/Default.wxl @@ -92,7 +92,7 @@ Select Customize to review current options. &Precompile standard library Download debugging &symbols Download debu&g binaries (requires VS 2017 or later) - Download &free-threaded binaries (experimental) + Download &free-threaded binaries [ActionLikeInstallation] Progress [ActionLikeInstalling]: