summaryrefslogtreecommitdiff
path: root/src/virtualenv/create
diff options
context:
space:
mode:
authorBernát Gábor <bgabor8@bloomberg.net>2020-02-23 18:52:30 +0000
committerGitHub <noreply@github.com>2020-02-23 18:52:30 +0000
commitef711b75ed8947e63f0d1e21ef34928239b8e545 (patch)
tree79356223dac98293e7470deb8fbbbddda2db5e63 /src/virtualenv/create
parent82b0d8b12adc3b7241e61d8d0d1a44c534362422 (diff)
downloadvirtualenv-ef711b75ed8947e63f0d1e21ef34928239b8e545.tar.gz
fix pypy2 builtins are imported as stdlib modules (#1656)
* fix pypy2 builtins are imported as stdlib modules Resolves #1652. Signed-off-by: Bernat Gabor <bgabor8@bloomberg.net> * test failure Signed-off-by: Bernat Gabor <bgabor8@bloomberg.net>
Diffstat (limited to 'src/virtualenv/create')
-rw-r--r--src/virtualenv/create/via_global_ref/builtin/pypy/pypy2.py9
-rw-r--r--src/virtualenv/create/via_global_ref/builtin/python2/python2.py15
-rw-r--r--src/virtualenv/create/via_global_ref/builtin/python2/site.py21
3 files changed, 32 insertions, 13 deletions
diff --git a/src/virtualenv/create/via_global_ref/builtin/pypy/pypy2.py b/src/virtualenv/create/via_global_ref/builtin/pypy/pypy2.py
index c3a9171..44edab6 100644
--- a/src/virtualenv/create/via_global_ref/builtin/pypy/pypy2.py
+++ b/src/virtualenv/create/via_global_ref/builtin/pypy/pypy2.py
@@ -2,6 +2,7 @@ from __future__ import absolute_import, unicode_literals
import abc
import logging
+import os
from six import add_metaclass
@@ -65,6 +66,14 @@ class PyPy2(PyPy, Python2):
logging.debug("no include folders as can't find include marker %s", host_include_marker)
return dirs
+ @property
+ def skip_rewrite(self):
+ """
+ PyPy2 built-in imports are handled by this path entry, don't overwrite to not disable it
+ see: https://github.com/pypa/virtualenv/issues/1652
+ """
+ return 'or value.endswith("lib_pypy{}__extensions__")'.format(os.sep)
+
class PyPy2Posix(PyPy2, PosixSupports):
"""PyPy 2 on POSIX"""
diff --git a/src/virtualenv/create/via_global_ref/builtin/python2/python2.py b/src/virtualenv/create/via_global_ref/builtin/python2/python2.py
index 4884f6e..f9e410a 100644
--- a/src/virtualenv/create/via_global_ref/builtin/python2/python2.py
+++ b/src/virtualenv/create/via_global_ref/builtin/python2/python2.py
@@ -32,16 +32,25 @@ class Python2(ViaGlobalRefVirtualenvBuiltin, Python2Supports):
else:
custom_site_text = custom_site.read_text()
expected = json.dumps([os.path.relpath(ensure_text(str(i)), ensure_text(str(site_py))) for i in self.libs])
+
custom_site_text = custom_site_text.replace("___EXPECTED_SITE_PACKAGES___", expected)
- custom_site_text = custom_site_text.replace(
- "# ___RELOAD_CODE___", os.linesep.join(" {}".format(i) for i in self.reload_code.splitlines()).lstrip()
- )
+
+ reload_code = os.linesep.join(" {}".format(i) for i in self.reload_code.splitlines()).lstrip()
+ custom_site_text = custom_site_text.replace("# ___RELOAD_CODE___", reload_code)
+
+ skip_rewrite = os.linesep.join(" {}".format(i) for i in self.skip_rewrite.splitlines()).lstrip()
+ custom_site_text = custom_site_text.replace("# ___SKIP_REWRITE____", skip_rewrite)
+
site_py.write_text(custom_site_text)
@property
def reload_code(self):
return 'reload(sys.modules["site"]) # noqa # call system site.py to setup import libraries'
+ @property
+ def skip_rewrite(self):
+ return ""
+
@classmethod
def sources(cls, interpreter):
for src in super(Python2, cls).sources(interpreter):
diff --git a/src/virtualenv/create/via_global_ref/builtin/python2/site.py b/src/virtualenv/create/via_global_ref/builtin/python2/site.py
index a2ffa9c..d0aafcd 100644
--- a/src/virtualenv/create/via_global_ref/builtin/python2/site.py
+++ b/src/virtualenv/create/via_global_ref/builtin/python2/site.py
@@ -86,16 +86,17 @@ def rewrite_standard_library_sys_path():
for at, value in enumerate(sys.path):
value = abs_path(value)
# replace old sys prefix path starts with new
- if value == exe_dir:
- pass # don't fix the current executable location, notably on Windows this gets added
- elif value.startswith(exe_dir):
- # content inside the exe folder needs to remap to original executables folder
- orig_exe_folder = base_executable[: base_executable.rfind(sep)]
- value = "{}{}".format(orig_exe_folder, value[len(exe_dir) :])
- elif value.startswith(prefix):
- value = "{}{}".format(base_prefix, value[len(prefix) :])
- elif value.startswith(exec_prefix):
- value = "{}{}".format(base_exec_prefix, value[len(exec_prefix) :])
+ skip_rewrite = value == exe_dir # don't fix the current executable location, notably on Windows this gets added
+ skip_rewrite = skip_rewrite # ___SKIP_REWRITE____
+ if not skip_rewrite:
+ if value.startswith(exe_dir):
+ # content inside the exe folder needs to remap to original executables folder
+ orig_exe_folder = base_executable[: base_executable.rfind(sep)]
+ value = "{}{}".format(orig_exe_folder, value[len(exe_dir) :])
+ elif value.startswith(prefix):
+ value = "{}{}".format(base_prefix, value[len(prefix) :])
+ elif value.startswith(exec_prefix):
+ value = "{}{}".format(base_exec_prefix, value[len(exec_prefix) :])
sys.path[at] = value