Skip to content

Commit bd98b65

Browse files
authored
gh-105084: Tests: Use setuptools+wheel from sysconfig.get_config_var('WHEEL_PKG_DIR') if set (#105056)
1 parent cda1bd3 commit bd98b65

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

Lib/test/support/__init__.py

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

22732273

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

22982318
cmd = [python, '-X', 'dev',
22992319
'-m', 'pip', 'install',
2300-
findfile('setuptools-67.6.1-py3-none-any.whl'),
2301-
findfile('wheel-0.40.0-py3-none-any.whl')]
2320+
_findwheel('setuptools'),
2321+
_findwheel('wheel')]
23022322
if verbose:
23032323
print()
23042324
print('Run:', ' '.join(cmd))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
When the Python build is configured ``--with-wheel-pkg-dir``, tests
2+
requiring the ``setuptools`` and ``wheel`` wheels will search for the wheels
3+
in ``WHEEL_PKG_DIR``.

0 commit comments

Comments
 (0)