From 682bbf96c6157c92bb737eacd425c0602dfc02f2 Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Tue, 11 Feb 2020 15:11:05 +0800 Subject: [PATCH] Always use PEP 405 sitecustomize --- tests/lib/venv.py | 65 ++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 37 deletions(-) diff --git a/tests/lib/venv.py b/tests/lib/venv.py index c80bf9aee2b..aba1736748a 100644 --- a/tests/lib/venv.py +++ b/tests/lib/venv.py @@ -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" @@ -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()