Fix site.getsitepackages() ignoring --system-site-packages on python2 (#2107)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
24f9a7faa6
commit
cc91e3f8a3
3 changed files with 34 additions and 1 deletions
1
docs/changelog/2106.bugfix.rst
Normal file
1
docs/changelog/2106.bugfix.rst
Normal file
|
|
@ -0,0 +1 @@
|
|||
Fix ``site.getsitepackages()`` ignoring ``--system-site-packages`` on python2 - by :user:`freundTech`.
|
||||
|
|
@ -158,7 +158,7 @@ def add_global_site_package():
|
|||
site.PREFIXES = [sys.base_prefix, sys.base_exec_prefix]
|
||||
site.main()
|
||||
finally:
|
||||
site.PREFIXES = orig_prefixes
|
||||
site.PREFIXES = orig_prefixes + site.PREFIXES
|
||||
|
||||
|
||||
main()
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
import ast
|
||||
import difflib
|
||||
import gc
|
||||
import json
|
||||
|
|
@ -621,3 +622,34 @@ def test_pth_in_site_vs_PYTHONPATH(tmp_path):
|
|||
env=env,
|
||||
)
|
||||
assert out == "ok\n"
|
||||
|
||||
|
||||
def test_getsitepackages_system_site(tmp_path):
|
||||
import site
|
||||
|
||||
old_prefixes = site.PREFIXES
|
||||
site.PREFIXES = [sys.base_prefix, sys.base_exec_prefix]
|
||||
system_site_packages = site.getsitepackages()
|
||||
site.PREFIXES = old_prefixes
|
||||
|
||||
# Test without --system-site-packages
|
||||
session = cli_run([ensure_text(str(tmp_path))])
|
||||
out = subprocess.check_output(
|
||||
[str(session.creator.exe), "-c", r"import site; print(site.getsitepackages())"],
|
||||
universal_newlines=True,
|
||||
)
|
||||
site_packages = ast.literal_eval(out)
|
||||
|
||||
for system_site_package in system_site_packages:
|
||||
assert system_site_package not in site_packages
|
||||
|
||||
# Test with --system-site-packages
|
||||
session = cli_run([ensure_text(str(tmp_path)), "--system-site-packages"])
|
||||
out = subprocess.check_output(
|
||||
[str(session.creator.exe), "-c", r"import site; print(site.getsitepackages())"],
|
||||
universal_newlines=True,
|
||||
)
|
||||
site_packages = ast.literal_eval(out)
|
||||
|
||||
for system_site_package in system_site_packages:
|
||||
assert system_site_package in site_packages
|
||||
|
|
|
|||
Loading…
Reference in a new issue