* 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
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()
================
)], 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):
--- /dev/null
+Disable user site packages directory when a ``._pth`` file is used, even if
+it contains ``import site``.
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: