Skip to content

Commit b2a3986

Browse files
committed
Eagerly import self_outdated_check when modifying pip
The self_outdated_check module should be loaded *before* pip is replaced as otherwise the module is liable to blow up if there are any incompatibities between the self_outdated_check from new pip and the old pip already loaded.
1 parent a7369ba commit b2a3986

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

news/12675.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Eagerly import the self version check logic to avoid crashes while upgrading
2+
or downgrading pip at the same time.

src/pip/_internal/commands/install.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,12 @@ def run(self, options: Values, args: List[str]) -> int:
406406
# If we're not replacing an already installed pip,
407407
# we're not modifying it.
408408
modifying_pip = pip_req.satisfied_by is None
409+
if modifying_pip:
410+
# Eagerly import this module to avoid crashes. Otherwise, this
411+
# module would be imported *after* pip was replaced, resulting in
412+
# crashes if the new self_outdated_check module was incompatible
413+
# with the rest of pip that's already imported.
414+
import pip._internal.self_outdated_check # noqa: F401
409415
protect_pip_from_modification_on_windows(modifying_pip=modifying_pip)
410416

411417
reqs_to_build = [

0 commit comments

Comments
 (0)