summaryrefslogtreecommitdiffstats
path: root/Lib/ensurepip
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2020-03-10 21:37:50 (GMT)
committerGitHub <noreply@github.com>2020-03-10 21:37:50 (GMT)
commit212acf544a41a983aea7166d43d8dfe9a8296655 (patch)
tree5018fc42e22f09ec3cf395d38fd53900e2d812b6 /Lib/ensurepip
parentb26ccfe3f989f87d4ae824eda8400ab796af8f8e (diff)
downloadcpython-212acf544a41a983aea7166d43d8dfe9a8296655.zip
cpython-212acf544a41a983aea7166d43d8dfe9a8296655.tar.gz
cpython-212acf544a41a983aea7166d43d8dfe9a8296655.tar.bz2
bpo-38662: ensurepip invokes pip via runpy (GH-18901)
The ensurepip module now invokes pip via the runpy module. Hence it is no longer tightly coupled with the internal API of the bundled pip version, allowing easier updates to a newer pip version both internally and for distributors. This way, any changes to the internal pip API won't mean ensurepip needs to be changed as well. Also, distributors can update their pip wheels independent on CPython release schedule. Co-Authored-By: Pradyun Gedam <pradyunsg@gmail.com> Co-Authored-By: Miro Hrončok <miro@hroncok.cz> (cherry picked from commit 88f82b2b9ea3514359cb6e3218121f75334063ac) Co-authored-by: Miro Hrončok <miro@hroncok.cz>
Diffstat (limited to 'Lib/ensurepip')
-rw-r--r--Lib/ensurepip/__init__.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/Lib/ensurepip/__init__.py b/Lib/ensurepip/__init__.py
index fc0edec..566fb2a 100644
--- a/Lib/ensurepip/__init__.py
+++ b/Lib/ensurepip/__init__.py
@@ -2,6 +2,7 @@ import os
import os.path
import pkgutil
import sys
+import runpy
import tempfile
@@ -23,9 +24,18 @@ def _run_pip(args, additional_paths=None):
if additional_paths is not None:
sys.path = additional_paths + sys.path
- # Install the bundled software
- import pip._internal
- return pip._internal.main(args)
+ # Invoke pip as if it's the main module, and catch the exit.
+ backup_argv = sys.argv[:]
+ sys.argv[1:] = args
+ try:
+ # run_module() alters sys.modules and sys.argv, but restores them at exit
+ runpy.run_module("pip", run_name="__main__", alter_sys=True)
+ except SystemExit as exc:
+ return exc.code
+ finally:
+ sys.argv[:] = backup_argv
+
+ raise SystemError("pip did not exit, this should never happen")
def version():