Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4a6dc3a

Browse files
committed
Close #20757: return success for skipped pip uninstall
The 3.4rc2 Windows uninstaller would fail if pip had been updated to a version that didn't match the version installed by ensurepip. This skip is no longer treated as an error, so an updated pip ends up being handled like any other pip installed package and is left alone by the CPython uninstaller.
1 parent 78c330d commit 4a6dc3a

3 files changed

Lines changed: 14 additions & 4 deletions

File tree

Lib/ensurepip/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,10 @@ def _uninstall_helper(*, verbosity=0):
128128

129129
# If the pip version doesn't match the bundled one, leave it alone
130130
if pip.__version__ != _PIP_VERSION:
131-
msg = ("ensurepip will only uninstall a matching pip "
131+
msg = ("ensurepip will only uninstall a matching version "
132132
"({!r} installed, {!r} bundled)")
133-
raise RuntimeError(msg.format(pip.__version__, _PIP_VERSION))
133+
print(msg.format(pip.__version__, _PIP_VERSION), file=sys.stderr)
134+
return
134135

135136
_require_ssl_for_pip()
136137
_disable_pip_configuration_settings()

Lib/test/test_ensurepip.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,12 @@ def test_uninstall_skipped_when_not_installed(self):
196196
ensurepip._uninstall_helper()
197197
self.run_pip.assert_not_called()
198198

199-
def test_uninstall_fails_with_wrong_version(self):
199+
def test_uninstall_skipped_with_warning_for_wrong_version(self):
200200
with fake_pip("not a valid version"):
201-
with self.assertRaises(RuntimeError):
201+
with test.support.captured_stderr() as stderr:
202202
ensurepip._uninstall_helper()
203+
warning = stderr.getvalue().strip()
204+
self.assertIn("only uninstall a matching version", warning)
203205
self.run_pip.assert_not_called()
204206

205207

Misc/NEWS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ Tests
3131

3232
- Issue #20743: Fix a reference leak in test_tcl.
3333

34+
Build
35+
-----
36+
37+
- Issue #20757: The ensurepip helper for the Windows uninstaller now skips
38+
uninstalling pip (rather than failing) if the user has updated pip to a
39+
different version from the one bundled with ensurepip.
40+
3441
Tools/Demos
3542
-----------
3643

0 commit comments

Comments
 (0)