Skip to content

Commit 9b0bd43

Browse files
committed
Tests: Use setuptools+wheel from sysconfig.get_config_var('WHEEL_PKG_DIR') if set
1 parent bfd20d2 commit 9b0bd43

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

Lib/test/support/__init__.py

+21-2
Original file line numberDiff line numberDiff line change
@@ -2271,6 +2271,25 @@ def requires_venv_with_pip():
22712271
return unittest.skipUnless(ctypes, 'venv: pip requires ctypes')
22722272

22732273

2274+
def _findwheel(pkgname):
2275+
"""Try to find a wheel with the package specified as pkgname.
2276+
2277+
If set, the wheels are searched for in WHEEL_PKG_DIR (see ensurepip).
2278+
Otherwise, they are searched for in the test directory.
2279+
"""
2280+
wheel_dir = sysconfig.get_config_var('WHEEL_PKG_DIR') or TEST_HOME_DIR
2281+
filenames = os.listdir(wheel_dir)
2282+
filenames = sorted(filenames) # sort this like ensurepip does it
2283+
for filename in filenames:
2284+
# filename is like 'pip-21.2.4-py3-none-any.whl'
2285+
if not filename.endswith(".whl"):
2286+
continue
2287+
prefix = pkgname + '-'
2288+
if filename.startswith(prefix):
2289+
return os.path.join(wheel_dir, filename)
2290+
raise FileNotFoundError(f"No wheel for {pkgname} found in {wheel_dir}")
2291+
2292+
22742293
# Context manager that creates a virtual environment, install setuptools and wheel in it
22752294
# and returns the path to the venv directory and the path to the python executable
22762295
@contextlib.contextmanager
@@ -2297,8 +2316,8 @@ def setup_venv_with_pip_setuptools_wheel(venv_dir):
22972316

22982317
cmd = [python, '-X', 'dev',
22992318
'-m', 'pip', 'install',
2300-
findfile('setuptools-67.6.1-py3-none-any.whl'),
2301-
findfile('wheel-0.40.0-py3-none-any.whl')]
2319+
_findwheel('setuptools'),
2320+
_findwheel('wheel')]
23022321
if verbose:
23032322
print()
23042323
print('Run:', ' '.join(cmd))

0 commit comments

Comments
 (0)