Skip to content

Commit

Permalink
gh-105084: Tests: Use setuptools+wheel from sysconfig.get_config_var(…
Browse files Browse the repository at this point in the history
…'WHEEL_PKG_DIR') if set (#105056)
  • Loading branch information
hroncok committed May 30, 2023
1 parent cda1bd3 commit bd98b65
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
24 changes: 22 additions & 2 deletions Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2271,6 +2271,26 @@ def requires_venv_with_pip():
return unittest.skipUnless(ctypes, 'venv: pip requires ctypes')


@functools.cache
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, reverse=True) # approximate "newest" first
for filename in filenames:
# filename is like 'setuptools-67.6.1-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
Expand All @@ -2297,8 +2317,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))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
When the Python build is configured ``--with-wheel-pkg-dir``, tests
requiring the ``setuptools`` and ``wheel`` wheels will search for the wheels
in ``WHEEL_PKG_DIR``.

0 comments on commit bd98b65

Please sign in to comment.