From de09cac82d6b2006b1e7e535f5635f90a08f0d41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Mon, 29 May 2023 13:15:11 +0200 Subject: [PATCH 1/5] Tests: Use setuptools+wheel from sysconfig.get_config_var('WHEEL_PKG_DIR') if set --- Lib/test/support/__init__.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index 7f8b1d71dbd227..5475febd7786de 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -2271,6 +2271,25 @@ def requires_venv_with_pip(): return unittest.skipUnless(ctypes, 'venv: pip requires ctypes') +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 '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 @@ -2297,8 +2316,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)) From 5698407135d28ea6a88225a9b93b8cb338e993ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Mon, 29 May 2023 13:41:46 +0200 Subject: [PATCH 2/5] Fixup: Sort wheel backwards, so wheel-0.40.0 comes before wheel-0.37.1 --- Lib/test/support/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index 5475febd7786de..b0825d632e982b 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -2279,7 +2279,7 @@ def _findwheel(pkgname): """ 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 + 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"): From 60f4072d1ffd68bf89c1060fb402498e8dc962bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Mon, 29 May 2023 13:45:22 +0200 Subject: [PATCH 3/5] Cache _findwheel --- Lib/test/support/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index b0825d632e982b..fee83432388856 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -2271,6 +2271,7 @@ 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. From 960f97260825c346b8863d5ad6ca449392083a0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Mon, 29 May 2023 14:49:49 +0200 Subject: [PATCH 4/5] Blurb --- .../next/Tests/2023-05-29-14-49-46.gh-issue-105056.lvVvoj.rst | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Misc/NEWS.d/next/Tests/2023-05-29-14-49-46.gh-issue-105056.lvVvoj.rst diff --git a/Misc/NEWS.d/next/Tests/2023-05-29-14-49-46.gh-issue-105056.lvVvoj.rst b/Misc/NEWS.d/next/Tests/2023-05-29-14-49-46.gh-issue-105056.lvVvoj.rst new file mode 100644 index 00000000000000..5f80d507147347 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2023-05-29-14-49-46.gh-issue-105056.lvVvoj.rst @@ -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``. From 63dddf2a84556bc9b9fa49f53d7a67f32c135170 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Tue, 30 May 2023 11:41:54 +0200 Subject: [PATCH 5/5] Reissue --- ....lvVvoj.rst => 2023-05-29-14-49-46.gh-issue-105084.lvVvoj.rst} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Misc/NEWS.d/next/Tests/{2023-05-29-14-49-46.gh-issue-105056.lvVvoj.rst => 2023-05-29-14-49-46.gh-issue-105084.lvVvoj.rst} (100%) diff --git a/Misc/NEWS.d/next/Tests/2023-05-29-14-49-46.gh-issue-105056.lvVvoj.rst b/Misc/NEWS.d/next/Tests/2023-05-29-14-49-46.gh-issue-105084.lvVvoj.rst similarity index 100% rename from Misc/NEWS.d/next/Tests/2023-05-29-14-49-46.gh-issue-105056.lvVvoj.rst rename to Misc/NEWS.d/next/Tests/2023-05-29-14-49-46.gh-issue-105084.lvVvoj.rst