Skip to content

Commit b4a0c8d

Browse files
miss-islingtonkimimgovstinner
authored
[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 73cc1fd) Co-authored-by: Imgyu Kim <kimimgo@gmail.com> Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent 70affe0 commit b4a0c8d

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
@@ -7,6 +7,7 @@
77
import unittest
88
import unittest.mock
99
from pathlib import Path
10+
from test.support import import_helper
1011

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

34+
def test_wheel_pkg_dir_none(self):
35+
# gh-146310: empty or None WHEEL_PKG_DIR should not search CWD
36+
for value in ('', None):
37+
with unittest.mock.patch('sysconfig.get_config_var',
38+
return_value=value) as get_config_var:
39+
module = import_helper.import_fresh_module('ensurepip')
40+
self.assertIsNone(module._WHEEL_PKG_DIR)
41+
get_config_var.assert_called_once_with('WHEEL_PKG_DIR')
42+
3343
def test_selected_wheel_path_no_dir(self):
3444
pip_filename = f'pip-{ensurepip._PIP_VERSION}-py3-none-any.whl'
3545
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)