python3.12/00401-tests-use-setuptools-...

59 lines
2.3 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <miro@hroncok.cz>
Date: Mon, 29 May 2023 15:51:16 +0200
Subject: [PATCH] 00401: Tests: Use setuptools+wheel from
sysconfig.get_config_var('WHEEL_PKG_DIR') if set
Proposed upstream https://github.com/python/cpython/pull/105056
---
Lib/test/support/__init__.py | 21 +++++++++++++++++++++
Lib/test/test_cppext.py | 4 ++--
2 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index d555c53fee..adc3f5901d 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -2398,5 +2398,26 @@ def adjust_int_max_str_digits(max_digits):
finally:
sys.set_int_max_str_digits(current)
+
+@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) # 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}")
+
+
#For recursion tests, easily exceeds default recursion limit
EXCEEDS_RECURSION_LIMIT = 5000
diff --git a/Lib/test/test_cppext.py b/Lib/test/test_cppext.py
index 4fb62d87e8..d124220dac 100644
--- a/Lib/test/test_cppext.py
+++ b/Lib/test/test_cppext.py
@@ -83,8 +83,8 @@ def run_cmd(operation, cmd):
cmd = [python, '-X', 'dev',
'-m', 'pip', 'install',
- support.findfile('setuptools-67.6.1-py3-none-any.whl'),
- support.findfile('wheel-0.40.0-py3-none-any.whl')]
+ support._findwheel('setuptools'),
+ support._findwheel('wheel')]
run_cmd('Install build dependencies', cmd)
# Build and install the C++ extension