mirror of
https://github.com/python/cpython.git
synced 2025-11-01 06:01:29 +00:00
gh-120037: Disable user site packages when a ._pth file is used (GH-137428)
This commit is contained in:
parent
e39255e76d
commit
7d06a0af17
4 changed files with 19 additions and 0 deletions
|
|
@ -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()
|
||||
================
|
||||
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
Disable user site packages directory when a ``._pth`` file is used, even if
|
||||
it contains ``import site``.
|
||||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue