Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix site.getsitepackages() ignoring --system-site-packages on python2 #2107

Merged
merged 2 commits into from
May 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog/2106.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix ``site.getsitepackages()`` ignoring ``--system-site-packages`` on python2 - by :user:`freundTech`.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
32 changes: 32 additions & 0 deletions tests/unit/create/test_creator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import absolute_import, unicode_literals

import ast
import difflib
import gc
import json
Expand Down Expand Up @@ -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