summaryrefslogtreecommitdiffstats
path: root/Lib/ensurepip/__init__.py
diff options
context:
space:
mode:
authorIgor Filatov <iafilatov@users.noreply.github.com>2017-09-25 01:03:24 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2017-09-25 01:03:24 (GMT)
commitcf7197ae43767c4346864e5b41246f628edd9b51 (patch)
tree31b2ad79968e1509a5b09ced5fc344346700640d /Lib/ensurepip/__init__.py
parentda86874a3d8f882d6aedd882b2e27f59b59d6798 (diff)
downloadcpython-cf7197ae43767c4346864e5b41246f628edd9b51.zip
cpython-cf7197ae43767c4346864e5b41246f628edd9b51.tar.gz
cpython-cf7197ae43767c4346864e5b41246f628edd9b51.tar.bz2
[2.7] bpo-31351: Set return code in ensurepip when pip fails (GH-3734)
Previously ensurepip would always report success, even if the pip installation failed. (cherry picked from commit 9adda0cdf89432386b7a04444a6199b580d287a1)
Diffstat (limited to 'Lib/ensurepip/__init__.py')
-rw-r--r--Lib/ensurepip/__init__.py24
1 files changed, 19 insertions, 5 deletions
diff --git a/Lib/ensurepip/__init__.py b/Lib/ensurepip/__init__.py
index c2abed8..ea2a5e6 100644
--- a/Lib/ensurepip/__init__.py
+++ b/Lib/ensurepip/__init__.py
@@ -29,7 +29,7 @@ def _run_pip(args, additional_paths=None):
# Install the bundled software
import pip
- pip.main(args)
+ return pip.main(args)
def version():
@@ -60,6 +60,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=True,
+ 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")
@@ -105,11 +120,10 @@ 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)
finally:
shutil.rmtree(tmpdir, ignore_errors=True)
-
def _uninstall_helper(verbosity=0):
"""Helper to support a clean default uninstall process on Windows
@@ -135,7 +149,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):
@@ -196,7 +210,7 @@ def _main(argv=None):
args = parser.parse_args(argv)
- bootstrap(
+ return _bootstrap(
root=args.root,
upgrade=args.upgrade,
user=args.user,