https://github.com/python/cpython/commit/b4a0c8defeaec40942dbc8a4a56fe926468fac45
commit: b4a0c8defeaec40942dbc8a4a56fe926468fac45
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: vstinner <[email protected]>
date: 2026-03-27T21:13:17Z
summary:
[3.14] gh-146310: Fix ensurepip to treat empty WHEEL_PKG_DIR as unset
(GH-146357) (#146534)
gh-146310: Fix ensurepip to treat empty WHEEL_PKG_DIR as unset (GH-146357)
Path('') resolves to CWD, so an empty WHEEL_PKG_DIR string caused
ensurepip to search the current working directory for wheel files.
Add a truthiness check to treat empty strings the same as None.
(cherry picked from commit 73cc1fd4f45b4daf2b2f9a6be69148775c7c2bff)
Co-authored-by: Imgyu Kim <[email protected]>
Co-authored-by: Victor Stinner <[email protected]>
files:
A Misc/NEWS.d/next/Library/2026-03-24-03-49-50.gh-issue-146310.WhlDir.rst
M Lib/ensurepip/__init__.py
M Lib/test/test_ensurepip.py
diff --git a/Lib/ensurepip/__init__.py b/Lib/ensurepip/__init__.py
index 3d5641e3576965..715389ea6c58bc 100644
--- a/Lib/ensurepip/__init__.py
+++ b/Lib/ensurepip/__init__.py
@@ -16,7 +16,8 @@
# policies recommend against bundling dependencies. For example, Fedora
# installs wheel packages in the /usr/share/python-wheels/ directory and don't
# install the ensurepip._bundled package.
-if (_pkg_dir := sysconfig.get_config_var('WHEEL_PKG_DIR')) is not None:
+_pkg_dir = sysconfig.get_config_var('WHEEL_PKG_DIR')
+if _pkg_dir:
_WHEEL_PKG_DIR = Path(_pkg_dir).resolve()
else:
_WHEEL_PKG_DIR = None
diff --git a/Lib/test/test_ensurepip.py b/Lib/test/test_ensurepip.py
index 6d3c91b0b6d9f9..a8bfbcd4abce99 100644
--- a/Lib/test/test_ensurepip.py
+++ b/Lib/test/test_ensurepip.py
@@ -7,6 +7,7 @@
import unittest
import unittest.mock
from pathlib import Path
+from test.support import import_helper
import ensurepip
import ensurepip._uninstall
@@ -30,6 +31,15 @@ def test_version_no_dir(self):
# when the bundled pip wheel is used, we get _PIP_VERSION
self.assertEqual(ensurepip._PIP_VERSION, ensurepip.version())
+ def test_wheel_pkg_dir_none(self):
+ # gh-146310: empty or None WHEEL_PKG_DIR should not search CWD
+ for value in ('', None):
+ with unittest.mock.patch('sysconfig.get_config_var',
+ return_value=value) as get_config_var:
+ module = import_helper.import_fresh_module('ensurepip')
+ self.assertIsNone(module._WHEEL_PKG_DIR)
+ get_config_var.assert_called_once_with('WHEEL_PKG_DIR')
+
def test_selected_wheel_path_no_dir(self):
pip_filename = f'pip-{ensurepip._PIP_VERSION}-py3-none-any.whl'
with unittest.mock.patch.object(ensurepip, '_WHEEL_PKG_DIR', None):
diff --git
a/Misc/NEWS.d/next/Library/2026-03-24-03-49-50.gh-issue-146310.WhlDir.rst
b/Misc/NEWS.d/next/Library/2026-03-24-03-49-50.gh-issue-146310.WhlDir.rst
new file mode 100644
index 00000000000000..b712595585201b
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2026-03-24-03-49-50.gh-issue-146310.WhlDir.rst
@@ -0,0 +1,2 @@
+The :mod:`ensurepip` module no longer looks for ``pip-*.whl`` wheel packages
+in the current directory.
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]