summaryrefslogtreecommitdiffstats
path: root/Lib/ensurepip
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/ensurepip')
-rw-r--r--Lib/ensurepip/__init__.py23
-rw-r--r--Lib/ensurepip/__main__.py3
-rw-r--r--Lib/ensurepip/_uninstall.py5
3 files changed, 24 insertions, 7 deletions
diff --git a/Lib/ensurepip/__init__.py b/Lib/ensurepip/__init__.py
index 9f5d151..d69e09f 100644
--- a/Lib/ensurepip/__init__.py
+++ b/Lib/ensurepip/__init__.py
@@ -25,7 +25,7 @@ def _run_pip(args, additional_paths=None):
# Install the bundled software
import pip
- pip.main(args)
+ return pip.main(args)
def version():
@@ -55,6 +55,21 @@ def bootstrap(*, root=None, upgrade=False, user=False,
Note that calling this function will alter both sys.path and os.environ.
"""
+ # Discard the return value
+ _bootstrap(root=root, upgrade=upgrade, user=user,
+ altinstall=altinstall, default_pip=default_pip,
+ verbosity=verbosity)
+
+
+def _bootstrap(*, root=None, upgrade=False, user=False,
+ altinstall=False, default_pip=False,
+ verbosity=0):
+ """
+ Bootstrap pip into the current Python installation (or the given root
+ directory). Returns pip command status code.
+
+ Note that calling this function will alter both sys.path and os.environ.
+ """
if altinstall and default_pip:
raise ValueError("Cannot use altinstall and default_pip together")
@@ -99,7 +114,7 @@ def bootstrap(*, root=None, upgrade=False, user=False,
if verbosity:
args += ["-" + "v" * verbosity]
- _run_pip(args + [p[0] for p in _PROJECTS], additional_paths)
+ return _run_pip(args + [p[0] for p in _PROJECTS], additional_paths)
def _uninstall_helper(*, verbosity=0):
"""Helper to support a clean default uninstall process on Windows
@@ -126,7 +141,7 @@ def _uninstall_helper(*, verbosity=0):
if verbosity:
args += ["-" + "v" * verbosity]
- _run_pip(args + [p[0] for p in reversed(_PROJECTS)])
+ return _run_pip(args + [p[0] for p in reversed(_PROJECTS)])
def _main(argv=None):
@@ -180,7 +195,7 @@ def _main(argv=None):
args = parser.parse_args(argv)
- bootstrap(
+ return _bootstrap(
root=args.root,
upgrade=args.upgrade,
user=args.user,
diff --git a/Lib/ensurepip/__main__.py b/Lib/ensurepip/__main__.py
index 77527d7..03eef0d 100644
--- a/Lib/ensurepip/__main__.py
+++ b/Lib/ensurepip/__main__.py
@@ -1,4 +1,5 @@
import ensurepip
+import sys
if __name__ == "__main__":
- ensurepip._main()
+ sys.exit(ensurepip._main())
diff --git a/Lib/ensurepip/_uninstall.py b/Lib/ensurepip/_uninstall.py
index 750365e..b257904 100644
--- a/Lib/ensurepip/_uninstall.py
+++ b/Lib/ensurepip/_uninstall.py
@@ -2,6 +2,7 @@
import argparse
import ensurepip
+import sys
def _main(argv=None):
@@ -23,8 +24,8 @@ def _main(argv=None):
args = parser.parse_args(argv)
- ensurepip._uninstall_helper(verbosity=args.verbosity)
+ return ensurepip._uninstall_helper(verbosity=args.verbosity)
if __name__ == "__main__":
- _main()
+ sys.exit(_main())