From c1a8427eb3b0c11d9d260b1311a0781ab28fa476 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 26 May 2026 17:57:51 +0200 Subject: [PATCH] gh-149879: Fix test_venv on Cygwin In copy mode, venv now also copies the cygpython DLL. Fix test_zippath_from_non_installed_posix(): copy also the cygpython DLL. --- Lib/test/test_venv.py | 7 +++++++ Lib/venv/__init__.py | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py index 9d2960664abfad5..1ff5d7cf0c51dd8 100644 --- a/Lib/test/test_venv.py +++ b/Lib/test/test_venv.py @@ -500,6 +500,7 @@ def test_executable_symlinks(self): # gh-124651: test quoted strings @unittest.skipIf(os.name == 'nt', 'contains invalid characters on Windows') + @unittest.skipIf(sys.platform == 'cygwin', 'fail to locate cygpython DLL') def test_special_chars_bash(self): """ Test that the template strings are quoted properly (bash) @@ -714,6 +715,12 @@ def test_zippath_from_non_installed_posix(self): os.mkdir(bindir) python_exe = os.path.basename(sys.executable) shutil.copy2(sys.executable, os.path.join(bindir, python_exe)) + if sys.platform == 'cygwin': + # Copy libpython DLL + exe_path = os.path.dirname(sys.executable) + libpython_dll = sysconfig.get_config_var('DLLLIBRARY') + shutil.copy2(os.path.join(exe_path, libpython_dll), + os.path.join(bindir, libpython_dll)) libdir = os.path.join(non_installed_dir, platlibdir, self.lib[1]) os.makedirs(libdir) landmark = os.path.join(libdir, "os.py") diff --git a/Lib/venv/__init__.py b/Lib/venv/__init__.py index 0653a43a8b17766..bd2762d55ef6961 100644 --- a/Lib/venv/__init__.py +++ b/Lib/venv/__init__.py @@ -319,6 +319,14 @@ def setup_python(self, context): if not os.path.islink(path): os.chmod(path, 0o755) + if not self.symlinks and sys.platform == 'cygwin': + # Copy libpython DLL + libpython_dll = sysconfig.get_config_var('DLLLIBRARY') + if not os.path.exists(os.path.join(binpath, libpython_dll)): + exe_path = os.path.dirname(sys.executable) + shutil.copy(os.path.join(exe_path, libpython_dll), + os.path.join(binpath, libpython_dll)) + else: def setup_python(self, context): """