From 9b0bd4351d7e4f8ef8e2bf1c10a2b323392dea8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Mon, 29 May 2023 13:15:11 +0200 Subject: [PATCH] Tests: Use setuptools+wheel from sysconfig.get_config_var('WHEEL_PKG_DIR') if set --- Lib/test/support/__init__.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index 7f8b1d71dbd227..d29ead0a9cf022 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -2271,6 +2271,25 @@ def requires_venv_with_pip(): return unittest.skipUnless(ctypes, 'venv: pip requires ctypes') +def _findwheel(pkgname): + """Try to find a wheel with the package specified as pkgname. + + If set, the wheels are searched for in WHEEL_PKG_DIR (see ensurepip). + Otherwise, they are searched for in the test directory. + """ + wheel_dir = sysconfig.get_config_var('WHEEL_PKG_DIR') or TEST_HOME_DIR + filenames = os.listdir(wheel_dir) + filenames = sorted(filenames) # sort this like ensurepip does it + for filename in filenames: + # filename is like 'pip-21.2.4-py3-none-any.whl' + if not filename.endswith(".whl"): + continue + prefix = pkgname + '-' + if filename.startswith(prefix): + return os.path.join(wheel_dir, filename) + raise FileNotFoundError(f"No wheel for {pkgname} found in {wheel_dir}") + + # Context manager that creates a virtual environment, install setuptools and wheel in it # and returns the path to the venv directory and the path to the python executable @contextlib.contextmanager @@ -2297,8 +2316,8 @@ def setup_venv_with_pip_setuptools_wheel(venv_dir): cmd = [python, '-X', 'dev', '-m', 'pip', 'install', - findfile('setuptools-67.6.1-py3-none-any.whl'), - findfile('wheel-0.40.0-py3-none-any.whl')] + _findwheel('setuptools'), + _findwheel('wheel')] if verbose: print() print('Run:', ' '.join(cmd))