diff options
| author | Bernát Gábor <bgabor8@bloomberg.net> | 2020-03-25 09:29:44 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-03-25 09:29:44 +0000 |
| commit | 7654e4dd908e52748a9df0de0a173811ddc51a73 (patch) | |
| tree | fdf796a953729a1fa4bb6adb78f5b3f212a7ad26 /src/virtualenv/create | |
| parent | c0ff71bf8d08da24677839aeb4eba1149f784d49 (diff) | |
| download | virtualenv-7654e4dd908e52748a9df0de0a173811ddc51a73.tar.gz | |
do not allow PYVENV_LAUNCHER to be set (#1749)
Signed-off-by: Bernat Gabor <bgabor8@bloomberg.net>
Diffstat (limited to 'src/virtualenv/create')
| -rw-r--r-- | src/virtualenv/create/via_global_ref/api.py | 22 | ||||
| -rw-r--r-- | src/virtualenv/create/via_global_ref/builtin/cpython/cpython3.py | 19 |
2 files changed, 32 insertions, 9 deletions
diff --git a/src/virtualenv/create/via_global_ref/api.py b/src/virtualenv/create/via_global_ref/api.py index aa864c8..e0e90a9 100644 --- a/src/virtualenv/create/via_global_ref/api.py +++ b/src/virtualenv/create/via_global_ref/api.py @@ -67,19 +67,23 @@ class ViaGlobalRefApi(Creator): ) def create(self): - self.patch_distutils_via_pth() + self.install_patch() - def patch_distutils_via_pth(self): + def install_patch(self): + text = self.env_patch_text() + if text: + pth = self.purelib / "_virtualenv.pth" + logging.debug("create virtualenv import hook file %s", pth) + pth.write_text("import _virtualenv") + dest_path = self.purelib / "_virtualenv.py" + logging.debug("create %s", dest_path) + dest_path.write_text(text) + + def env_patch_text(self): """Patch the distutils package to not be derailed by its configuration files""" with ensure_file_on_disk(Path(__file__).parent / "_virtualenv.py", self.app_data) as resolved_path: text = resolved_path.read_text() - text = text.replace('"__SCRIPT_DIR__"', repr(os.path.relpath(str(self.script_dir), str(self.purelib)))) - dest_path = self.purelib / "_virtualenv.py" - logging.debug("create %s", dest_path) - dest_path.write_text(text) - pth = self.purelib / "_virtualenv.pth" - logging.debug("create virtualenv import hook file %s", pth) - pth.write_text("import _virtualenv") + return text.replace('"__SCRIPT_DIR__"', repr(os.path.relpath(str(self.script_dir), str(self.purelib)))) def _args(self): return super(ViaGlobalRefApi, self)._args() + [("global", self.enable_system_site_package)] diff --git a/src/virtualenv/create/via_global_ref/builtin/cpython/cpython3.py b/src/virtualenv/create/via_global_ref/builtin/cpython/cpython3.py index 589544c..3e49a52 100644 --- a/src/virtualenv/create/via_global_ref/builtin/cpython/cpython3.py +++ b/src/virtualenv/create/via_global_ref/builtin/cpython/cpython3.py @@ -1,6 +1,7 @@ from __future__ import absolute_import, unicode_literals import abc +from textwrap import dedent from six import add_metaclass @@ -22,6 +23,24 @@ class CPython3Posix(CPythonPosix, CPython3): def can_describe(cls, interpreter): return is_mac_os_framework(interpreter) is False and super(CPython3Posix, cls).can_describe(interpreter) + def env_patch_text(self): + text = super(CPython3Posix, self).env_patch_text() + if self.pyvenv_launch_patch_active(self.interpreter): + text += dedent( + """ + # for https://github.com/python/cpython/pull/9516, see https://github.com/pypa/virtualenv/issues/1704 + import os + if "__PYVENV_LAUNCHER__" in os.environ: + del os.environ["__PYVENV_LAUNCHER__"] + """ + ) + return text + + @classmethod + def pyvenv_launch_patch_active(cls, interpreter): + ver = interpreter.version_info + return interpreter.platform == "darwin" and ((3, 7, 8) > ver >= (3, 7) or (3, 8, 3) > ver >= (3, 8)) + class CPython3Windows(CPythonWindows, CPython3): """""" |
