|
3 | 3 | import sys |
4 | 4 | import runpy |
5 | 5 | import tempfile |
| 6 | +import subprocess |
6 | 7 | from importlib import resources |
7 | 8 |
|
8 | 9 | from . import _bundled |
|
14 | 15 |
|
15 | 16 | _SETUPTOOLS_VERSION = "49.2.1" |
16 | 17 |
|
17 | | -_PIP_VERSION = "20.2.1" |
| 18 | +_PIP_VERSION = "20.2.3" |
18 | 19 |
|
19 | 20 | _PROJECTS = [ |
20 | 21 | ("setuptools", _SETUPTOOLS_VERSION, "py3"), |
|
23 | 24 |
|
24 | 25 |
|
25 | 26 | 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 |
42 | 39 |
|
43 | 40 |
|
44 | 41 | def version(): |
|
0 commit comments