Skip to content

Commit

Permalink
Always use PEP 405 sitecustomize
Browse files Browse the repository at this point in the history
  • Loading branch information
uranusjr committed Feb 12, 2020
1 parent ac8cec6 commit 682bbf9
Showing 1 changed file with 28 additions and 37 deletions.
65 changes: 28 additions & 37 deletions tests/lib/venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,35 +74,33 @@ def _create(self, clear=False):
self.user_site_packages = self._user_site_packages

def _customize_site(self):
contents = ''
if self._venv_type == 'venv':
# Enable user site (before system).
contents += textwrap.dedent(
'''
import os, site, sys
if not os.environ.get('PYTHONNOUSERSITE', False):
site.ENABLE_USER_SITE = True
# First, drop system-sites related paths.
original_sys_path = sys.path[:]
known_paths = set()
for path in site.getsitepackages():
site.addsitedir(path, known_paths=known_paths)
system_paths = sys.path[len(original_sys_path):]
for path in system_paths:
if path in original_sys_path:
original_sys_path.remove(path)
sys.path = original_sys_path
# Second, add user-site.
site.addsitedir(site.getusersitepackages())
# Third, add back system-sites related paths.
for path in site.getsitepackages():
site.addsitedir(path)
''').strip()
# Enable user site (before system).
contents = textwrap.dedent(
'''
import os, site, sys
if not os.environ.get('PYTHONNOUSERSITE', False):
site.ENABLE_USER_SITE = True
# First, drop system-sites related paths.
original_sys_path = sys.path[:]
known_paths = set()
for path in site.getsitepackages():
site.addsitedir(path, known_paths=known_paths)
system_paths = sys.path[len(original_sys_path):]
for path in system_paths:
if path in original_sys_path:
original_sys_path.remove(path)
sys.path = original_sys_path
# Second, add user-site.
site.addsitedir(site.getusersitepackages())
# Third, add back system-sites related paths.
for path in site.getsitepackages():
site.addsitedir(path)
''').strip()
if self._sitecustomize is not None:
contents += '\n' + self._sitecustomize
sitecustomize = self.site / "sitecustomize.py"
Expand Down Expand Up @@ -134,11 +132,4 @@ def user_site_packages(self):
@user_site_packages.setter
def user_site_packages(self, value):
self._user_site_packages = value
if self._venv_type == 'virtualenv':
marker = self.lib / "no-global-site-packages.txt"
if self._user_site_packages:
marker.unlink()
else:
marker.touch()
elif self._venv_type == 'venv':
self._customize_site()
self._customize_site()

0 comments on commit 682bbf9

Please sign in to comment.