diff options
| author | reksarka <reksarka@gmail.com> | 2022-06-25 03:11:17 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-25 01:11:17 +0100 |
| commit | 805dcffe002abf8a161be67358a5cc1422332e14 (patch) | |
| tree | 61e7e0936bbf3f04c38a835ad137d8b39dfcdb4b /src/virtualenv/create | |
| parent | b01515bce60dd00723546ec022e0549fcfab3cfb (diff) | |
| download | virtualenv-805dcffe002abf8a161be67358a5cc1422332e14.tar.gz | |
Windows embedable support (#2353)
* Bump pip and setuptools (#2348)
Signed-off-by: Bernát Gábor <bgabor8@bloomberg.net>
* Use shlex.quote instead of deprecated pipes.quote (#2351)
* Embeds the "python<VERSION>.zip" for Windows.
For example, for Python 3.10 the embeddable file name would be
"python310.zip". If this file would be found in `sys.path`, the
virtualenv should copy it into the "<venv>\Scripts\python310.zip".
* For Windows CPython3: *.dll/*.pyd -> to_bin
* Fixture for a Python interpreter info.
Helps to test virtualenv creator classes.
* Creators tests: path_mock as separate module.
* Clarifies tests, separates testing tools.
* Tests for CPython3Windows sources.
* Tests for the embedded Python std lib for Windows.
* Add news entry.
* Replaces `yield from` for backward compability.
* FIX: Path mocking in pypy tests.
* Wrap `sys` `Path` with `str` for importlib.
The importlib accepts a Path-like objects from Python 3.6
* Makes PathMock ABC compatible with Python 2
* Does not collect tests for Python3 under Python 2
It is possible to make pass CPython3 tests under Python 2,
but it's better to disable it instead of decreasing the
readability and performance of Python 3 style.
* Allows empty `Path()` in Windows with Python 2
* Allows to load fixture files with PY2 Windows Path
* Skips one PY3 POSIX test in PY2 Windows
Co-authored-by: Bernát Gábor <gaborjbernat@gmail.com>
Co-authored-by: Lumír 'Frenzy' Balhar <lbalhar@redhat.com>
Diffstat (limited to 'src/virtualenv/create')
| -rw-r--r-- | src/virtualenv/create/via_global_ref/builtin/cpython/cpython3.py | 49 |
1 files changed, 40 insertions, 9 deletions
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 fcd92b8..3bbc494 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,9 @@ from __future__ import absolute_import, unicode_literals import abc +import fnmatch +from itertools import chain +from operator import methodcaller as method from textwrap import dedent from six import add_metaclass @@ -53,11 +56,20 @@ class CPython3Windows(CPythonWindows, CPython3): @classmethod def sources(cls, interpreter): - for src in super(CPython3Windows, cls).sources(interpreter): - yield src - if not cls.has_shim(interpreter): - for src in cls.include_dll_and_pyd(interpreter): - yield src + if cls.has_shim(interpreter): + refs = cls.executables(interpreter) + else: + refs = chain( + cls.executables(interpreter), + cls.dll_and_pyd(interpreter), + cls.python_zip(interpreter), + ) + for ref in refs: + yield ref + + @classmethod + def executables(cls, interpreter): + return super(CPython3Windows, cls).sources(interpreter) @classmethod def has_shim(cls, interpreter): @@ -79,13 +91,32 @@ class CPython3Windows(CPythonWindows, CPython3): return super(CPython3Windows, cls).host_python(interpreter) @classmethod - def include_dll_and_pyd(cls, interpreter): + def dll_and_pyd(cls, interpreter): dll_folder = Path(interpreter.system_prefix) / "DLLs" host_exe_folder = Path(interpreter.system_executable).parent for folder in [host_exe_folder, dll_folder]: for file in folder.iterdir(): if file.suffix in (".pyd", ".dll"): - yield PathRefToDest(file, dest=cls.to_dll_and_pyd) + yield PathRefToDest(file, cls.to_bin) - def to_dll_and_pyd(self, src): - return self.bin_dir / src.name + @classmethod + def python_zip(cls, interpreter): + """ + "python{VERSION}.zip" contains compiled *.pyc std lib packages, where + "VERSION" is `py_version_nodot` var from the `sysconfig` module. + :see: https://docs.python.org/3/using/windows.html#the-embeddable-package + :see: `discovery.py_info.PythonInfo` class (interpreter). + :see: `python -m sysconfig` output. + + :note: The embeddable Python distribution for Windows includes + "python{VERSION}.zip" and "python{VERSION}._pth" files. User can + move/rename *zip* file and edit `sys.path` by editing *_pth* file. + Here the `pattern` is used only for the default *zip* file name! + """ + pattern = "*python{}.zip".format(interpreter.version_nodot) + matches = fnmatch.filter(interpreter.path, pattern) + matched_paths = map(Path, matches) + existing_paths = filter(method("exists"), matched_paths) + path = next(existing_paths, None) + if path is not None: + yield PathRefToDest(path, cls.to_bin) |
