summaryrefslogtreecommitdiff
path: root/src/virtualenv/create
diff options
context:
space:
mode:
authorDavid Tucker <48501491+tucked@users.noreply.github.com>2020-03-13 10:11:31 -0700
committerGitHub <noreply@github.com>2020-03-13 17:11:31 +0000
commitf1663de39c34803761a53eba4d3b39cc59ed1560 (patch)
treef5e656727bfb99060a3a0675a145c7b3abc8fe29 /src/virtualenv/create
parent3816e7c7881bdc9ca99e18fe69810c856c9a9d2d (diff)
downloadvirtualenv-f1663de39c34803761a53eba4d3b39cc59ed1560.tar.gz
Allow missing .py files if .pyc is present (#1714)
* Allow missing .py files if .pyc is present * Document packaging types we support Signed-off-by: Bernat Gabor <bgabor8@bloomberg.net> * improve test Signed-off-by: Bernat Gabor <bgabor8@bloomberg.net> * PyPy requires the standard library source files Signed-off-by: Bernat Gabor <bgabor8@bloomberg.net> Co-authored-by: Bernat Gabor <bgabor8@bloomberg.net>
Diffstat (limited to 'src/virtualenv/create')
-rw-r--r--src/virtualenv/create/via_global_ref/builtin/cpython/cpython2.py4
-rw-r--r--src/virtualenv/create/via_global_ref/builtin/pypy/pypy2.py4
-rw-r--r--src/virtualenv/create/via_global_ref/builtin/python2/python2.py26
3 files changed, 29 insertions, 5 deletions
diff --git a/src/virtualenv/create/via_global_ref/builtin/cpython/cpython2.py b/src/virtualenv/create/via_global_ref/builtin/cpython/cpython2.py
index c46a95e..6a8871b 100644
--- a/src/virtualenv/create/via_global_ref/builtin/cpython/cpython2.py
+++ b/src/virtualenv/create/via_global_ref/builtin/cpython/cpython2.py
@@ -26,6 +26,10 @@ class CPython2(CPython, Python2):
yield PathRefToDest(host_include_marker.parent, dest=lambda self, _: self.include)
@classmethod
+ def needs_stdlib_py_module(cls):
+ return False
+
+ @classmethod
def host_include_marker(cls, interpreter):
return Path(interpreter.system_include) / "Python.h"
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 c7288da..020000b 100644
--- a/src/virtualenv/create/via_global_ref/builtin/pypy/pypy2.py
+++ b/src/virtualenv/create/via_global_ref/builtin/pypy/pypy2.py
@@ -32,6 +32,10 @@ class PyPy2(PyPy, Python2):
yield PathRefToDest(host_include_marker.parent, dest=lambda self, _: self.include)
@classmethod
+ def needs_stdlib_py_module(cls):
+ return True
+
+ @classmethod
def host_include_marker(cls, interpreter):
return Path(interpreter.system_include) / "PyPy.h"
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 7c8acf3..22d1da0 100644
--- a/src/virtualenv/create/via_global_ref/builtin/python2/python2.py
+++ b/src/virtualenv/create/via_global_ref/builtin/python2/python2.py
@@ -57,11 +57,27 @@ class Python2(ViaGlobalRefVirtualenvBuiltin, Python2Supports):
yield src
# install files needed to run site.py
for req in cls.modules():
- stdlib_path = interpreter.stdlib_path("{}.py".format(req))
- yield PathRefToDest(stdlib_path, dest=cls.to_stdlib)
- comp = stdlib_path.parent / "{}.pyc".format(req)
- if comp.exists():
- yield PathRefToDest(comp, dest=cls.to_stdlib)
+
+ # the compiled path is optional, but refer to it if exists
+ module_compiled_path = interpreter.stdlib_path("{}.pyc".format(req))
+ has_compile = module_compiled_path.exists()
+ if has_compile:
+ yield PathRefToDest(module_compiled_path, dest=cls.to_stdlib)
+
+ # stdlib module src may be missing if the interpreter allows it by falling back to the compiled
+ module_path = interpreter.stdlib_path("{}.py".format(req))
+ add_py_module = cls.needs_stdlib_py_module()
+ if add_py_module is False:
+ if module_path.exists(): # if present add it
+ add_py_module = True
+ else:
+ add_py_module = not has_compile # otherwise only add it if the pyc is not present
+ if add_py_module:
+ yield PathRefToDest(module_path, dest=cls.to_stdlib)
+
+ @classmethod
+ def needs_stdlib_py_module(cls):
+ raise NotImplementedError
def to_stdlib(self, src):
return self.stdlib / src.name