@@ -2271,6 +2271,26 @@ def requires_venv_with_pip():
2271
2271
return unittest .skipUnless (ctypes , 'venv: pip requires ctypes' )
2272
2272
2273
2273
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
+
2274
2294
# Context manager that creates a virtual environment, install setuptools and wheel in it
2275
2295
# and returns the path to the venv directory and the path to the python executable
2276
2296
@contextlib .contextmanager
@@ -2297,8 +2317,8 @@ def setup_venv_with_pip_setuptools_wheel(venv_dir):
2297
2317
2298
2318
cmd = [python , '-X' , 'dev' ,
2299
2319
'-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' )]
2302
2322
if verbose :
2303
2323
print ()
2304
2324
print ('Run:' , ' ' .join (cmd ))
0 commit comments