8000 bpo-41490: Bump vendored pip to version 20.2.3 · python/cpython@44790de · GitHub
[go: up one dir, main page]

Skip to content

Commit 44790de

Browse files
committed
bpo-41490: Bump vendored pip to version 20.2.3
1 parent d646e91 commit 44790de

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

Lib/ensurepip/__init__.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import sys
44
import runpy
55
import tempfile
6+
import subprocess
67
from importlib import resources
78

89
from . import _bundled
@@ -14,7 +15,7 @@
1415

1516
_SETUPTOOLS_VERSION = "47.1.0"
1617

17-
_PIP_VERSION = "20.1.1"
18+
_PIP_VERSION = "20.2.3"
1819

1920
_PROJECTS = [
2021
("setuptools", _SETUPTOOLS_VERSION, "py3"),
@@ -23,22 +24,18 @@
2324

2425

2526
def _run_pip(args, additional_paths=None):
26-
# Add our bundled software to the sys.path so we can import it
27-
if additional_paths is not None:
28-
sys.path = additional_paths + sys.path
29-
30-
# Invoke pip as if it's the main module, and catch the exit.
31-
backup_argv = sys.argv[:]
32-
sys.argv[1:] = args
33-
try:
34-
# run_module() alters sys.modules and sys.argv, but restores them at exit
35-
runpy.run_module("pip", run_name="__main__", alter_sys=True)
36-
except SystemExit as exc:
37-
return exc.code
38-
finally:
39-
sys.argv[:] = backup_argv
40-
41-
raise SystemError("pip did not exit, this should never happen")
27+
# Run the bootstraping in a subprocess to avoid leaking any state that happens
28+
# after pip has executed. Particulary, this avoids the case when pip holds onto
29+
# the files in *additional_paths*, preventing us to remove them at the end of the
30+
# invocation.
31+
code = f"""
32+
import runpy
33+
import sys
34+
sys.path = {additional_paths or []} + sys.path
35+
sys.argv[1:] = {args}
36+
runpy.run_module("pip", run_name="__main__", alter_sys=True)
37+
"""
38+
return subprocess.run([sys.executable, "-c", code], check=True).returncode
4239

4340

4441
def version():

0 commit comments

Comments
 (0)
0