summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBernát Gábor <bgabor8@bloomberg.net>2020-04-26 16:16:59 +0100
committerGitHub <noreply@github.com>2020-04-26 16:16:59 +0100
commitdfafc1102a0746f3fe6efdee3520a8d83e88b9ef (patch)
tree8c04f955ea277a5fb06c340774cf18c87f59fb56 /src
parent078c945c861d53910481fb0c97d70f1d42cacfb9 (diff)
downloadvirtualenv-dfafc1102a0746f3fe6efdee3520a8d83e88b9ef.tar.gz
Ensure makefile is present on CPython2 POSIX (#1787)
Diffstat (limited to 'src')
-rw-r--r--src/virtualenv/create/debug.py23
-rw-r--r--src/virtualenv/create/via_global_ref/builtin/cpython/cpython2.py18
-rw-r--r--src/virtualenv/create/via_global_ref/builtin/cpython/mac_os.py4
-rw-r--r--src/virtualenv/create/via_global_ref/builtin/ref.py2
-rw-r--r--src/virtualenv/discovery/py_info.py9
5 files changed, 48 insertions, 8 deletions
diff --git a/src/virtualenv/create/debug.py b/src/virtualenv/create/debug.py
index d015be6..23c380c 100644
--- a/src/virtualenv/create/debug.py
+++ b/src/virtualenv/create/debug.py
@@ -51,6 +51,14 @@ def run():
result["sys"]["fs_encoding"] = sys.getfilesystemencoding()
result["sys"]["io_encoding"] = getattr(sys.stdout, "encoding", None)
result["version"] = sys.version
+
+ try:
+ import sysconfig
+
+ result["makefile_filename"] = encode_path(sysconfig.get_makefile_filename())
+ except ImportError:
+ pass
+
import os # landmark
result["os"] = repr(os)
@@ -84,11 +92,16 @@ def run():
import json
result["json"] = repr(json)
- print(json.dumps(result, indent=2))
- except (ImportError, ValueError, TypeError) as exception: # pragma: no cover
- result["json"] = repr(exception) # pragma: no cover
- print(repr(result)) # pragma: no cover
- raise SystemExit(1) # pragma: no cover
+ except ImportError as exception:
+ result["json"] = repr(exception)
+ else:
+ try:
+ content = json.dumps(result, indent=2)
+ sys.stdout.write(content)
+ except (ValueError, TypeError) as exception: # pragma: no cover
+ sys.stderr.write(repr(exception))
+ sys.stdout.write(repr(result)) # pragma: no cover
+ raise SystemExit(1) # pragma: no cover
if __name__ == "__main__":
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 61aa395..555b0c5 100644
--- a/src/virtualenv/create/via_global_ref/builtin/cpython/cpython2.py
+++ b/src/virtualenv/create/via_global_ref/builtin/cpython/cpython2.py
@@ -54,7 +54,23 @@ class CPython2(CPython, Python2):
return dirs
-class CPython2Posix(CPython2, CPythonPosix):
+@add_metaclass(abc.ABCMeta)
+class CPython2PosixBase(CPython2, CPythonPosix):
+ """common to macOs framework builds and other posix CPython2"""
+
+ @classmethod
+ def sources(cls, interpreter):
+ for src in super(CPython2PosixBase, cls).sources(interpreter):
+ yield src
+
+ # check if the makefile exists and if so make it available under the virtual environment
+ make_file = Path(interpreter.sysconfig["makefile_filename"])
+ if make_file.exists() and str(make_file).startswith(interpreter.prefix):
+ under_prefix = make_file.relative_to(Path(interpreter.prefix))
+ yield PathRefToDest(make_file, dest=lambda self, s: self.dest / under_prefix)
+
+
+class CPython2Posix(CPython2PosixBase):
"""CPython 2 on POSIX (excluding macOs framework builds)"""
@classmethod
diff --git a/src/virtualenv/create/via_global_ref/builtin/cpython/mac_os.py b/src/virtualenv/create/via_global_ref/builtin/cpython/mac_os.py
index b7ffaf1..7967a81 100644
--- a/src/virtualenv/create/via_global_ref/builtin/cpython/mac_os.py
+++ b/src/virtualenv/create/via_global_ref/builtin/cpython/mac_os.py
@@ -14,7 +14,7 @@ from virtualenv.util.path import Path
from virtualenv.util.six import ensure_text
from .common import CPython, CPythonPosix, is_mac_os_framework
-from .cpython2 import CPython2
+from .cpython2 import CPython2PosixBase
from .cpython3 import CPython3
@@ -65,7 +65,7 @@ class CPythonmacOsFramework(CPython):
raise NotImplementedError
-class CPython2macOsFramework(CPythonmacOsFramework, CPython2, CPythonPosix):
+class CPython2macOsFramework(CPythonmacOsFramework, CPython2PosixBase):
@classmethod
def image_ref(cls, interpreter):
return Path(interpreter.prefix) / "Python"
diff --git a/src/virtualenv/create/via_global_ref/builtin/ref.py b/src/virtualenv/create/via_global_ref/builtin/ref.py
index 9022994..263da3b 100644
--- a/src/virtualenv/create/via_global_ref/builtin/ref.py
+++ b/src/virtualenv/create/via_global_ref/builtin/ref.py
@@ -122,6 +122,8 @@ class PathRefToDest(PathRef):
dest = self.dest(creator, self.src)
method = self.method(symlinks)
dest_iterable = dest if isinstance(dest, list) else (dest,)
+ if not dest.parent.exists():
+ dest.parent.mkdir(parents=True, exist_ok=True)
for dst in dest_iterable:
method(self.src, dst)
diff --git a/src/virtualenv/discovery/py_info.py b/src/virtualenv/discovery/py_info.py
index 6d76cbe..516faf1 100644
--- a/src/virtualenv/discovery/py_info.py
+++ b/src/virtualenv/discovery/py_info.py
@@ -75,6 +75,15 @@ class PythonInfo(object):
self.stdout_encoding = u(getattr(sys.stdout, "encoding", None))
self.sysconfig_paths = {u(i): u(sysconfig.get_path(i, expand=False)) for i in sysconfig.get_path_names()}
+
+ self.sysconfig = {
+ u(k): u(v)
+ for k, v in [ # a list of content to store from sysconfig
+ ("makefile_filename", sysconfig.get_makefile_filename()),
+ ]
+ if k is not None
+ }
+
config_var_keys = set()
for element in self.sysconfig_paths.values():
for k in _CONF_VAR_RE.findall(element):