From d73ab1276304d002a9f2e19467980c16784b68fd Mon Sep 17 00:00:00 2001 From: reksarka Date: Tue, 28 Jun 2022 18:37:33 +0300 Subject: [PATCH] Ignores missing DLLs dir in CPython3Windows This dir can be missing in some Python distributions, e.g. in the embeddable Python for Windows. This fix prevents the error described in https://github.com/pypa/virtualenv/issues/2368 Also fixes tests that were broken by prev commit. --- .../create/via_global_ref/builtin/cpython/cpython3.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 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 3bbc494a6..03d30975a 100644 --- a/src/virtualenv/create/via_global_ref/builtin/cpython/cpython3.py +++ b/src/virtualenv/create/via_global_ref/builtin/cpython/cpython3.py @@ -92,9 +92,15 @@ def host_python(cls, interpreter): @classmethod def dll_and_pyd(cls, interpreter): + folders = [Path(interpreter.system_executable).parent] + + # May be missing on some Python hosts. + # See https://github.com/pypa/virtualenv/issues/2368 dll_folder = Path(interpreter.system_prefix) / "DLLs" - host_exe_folder = Path(interpreter.system_executable).parent - for folder in [host_exe_folder, dll_folder]: + if dll_folder.is_dir(): + folders.append(dll_folder) + + for folder in folders: for file in folder.iterdir(): if file.suffix in (".pyd", ".dll"): yield PathRefToDest(file, cls.to_bin)