Skip to content

Commit 78b8716

Browse files
miss-islingtonkimimgovstinner
authored
[3.13] gh-146310: Fix ensurepip to treat empty WHEEL_PKG_DIR as unset (GH-146357) (#146535)
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 73cc1fd) Co-authored-by: Imgyu Kim <kimimgo@gmail.com> Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent b0fab92 commit 78b8716

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

Lib/ensurepip/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
# policies recommend against bundling dependencies. For example, Fedora
1717
# installs wheel packages in the /usr/share/python-wheels/ directory and don't
1818
# install the ensurepip._bundled package.
19-
if (_pkg_dir := sysconfig.get_config_var('WHEEL_PKG_DIR')) is not None:
19+
_pkg_dir = sysconfig.get_config_var('WHEEL_PKG_DIR')
20+
if _pkg_dir:
2021
_WHEEL_PKG_DIR = Path(_pkg_dir).resolve()
2122
else:
2223
_WHEEL_PKG_DIR = None

Lib/test/test_ensurepip.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import unittest.mock
99
from importlib.resources.abc import Traversable
1010
from pathlib import Path
11+
from test.support import import_helper
1112

1213
import ensurepip
1314
import ensurepip._uninstall
@@ -31,6 +32,15 @@ def test_version_no_dir(self):
3132
# when the bundled pip wheel is used, we get _PIP_VERSION
3233
self.assertEqual(ensurepip._PIP_VERSION, ensurepip.version())
3334

35+
def test_wheel_pkg_dir_none(self):
36+
# gh-146310: empty or None WHEEL_PKG_DIR should not search CWD
37+
for value in ('', None):
38+
with unittest.mock.patch('sysconfig.get_config_var',
39+
return_value=value) as get_config_var:
40+
module = import_helper.import_fresh_module('ensurepip')
41+
self.assertIsNone(module._WHEEL_PKG_DIR)
42+
get_config_var.assert_called_once_with('WHEEL_PKG_DIR')
43+
3444
def test_selected_wheel_path_no_dir(self):
3545
pip_filename = f'pip-{ensurepip._PIP_VERSION}-py3-none-any.whl'
3646
with unittest.mock.patch.object(ensurepip, '_WHEEL_PKG_DIR', None):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The :mod:`ensurepip` module no longer looks for ``pip-*.whl`` wheel packages
2+
in the current directory.

0 commit comments

Comments
 (0)