Author: Matti Picus <[email protected]>
Branch:
Changeset: r97869:17694ed47a34
Date: 2019-10-27 20:32 +0200
http://bitbucket.org/pypy/pypy/changeset/17694ed47a34/
Log: backport ensurepip from 3.6
diff --git a/lib-python/2.7/ensurepip/__init__.py
b/lib-python/2.7/ensurepip/__init__.py
--- a/lib-python/2.7/ensurepip/__init__.py
+++ b/lib-python/2.7/ensurepip/__init__.py
@@ -4,7 +4,6 @@
import os
import os.path
import pkgutil
-import shutil
import sys
import tempfile
@@ -28,8 +27,8 @@
sys.path = additional_paths + sys.path
# Install the bundled software
- import pip
- pip.main(args)
+ import pip._internal
+ return pip._internal.main(args)
def version():
@@ -38,7 +37,6 @@
"""
return _PIP_VERSION
-
def _disable_pip_configuration_settings():
# We deliberately ignore all pip environment variables
# when invoking pip
@@ -52,7 +50,7 @@
def bootstrap(root=None, upgrade=False, user=False,
- altinstall=False, default_pip=True,
+ altinstall=False, default_pip=False,
verbosity=0):
"""
Bootstrap pip into the current Python installation (or the given root
@@ -60,6 +58,21 @@
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")
@@ -78,8 +91,7 @@
# omit pip and easy_install
os.environ["ENSUREPIP_OPTIONS"] = "install"
- tmpdir = tempfile.mkdtemp()
- try:
+ with tempfile.TemporaryDirectory() as tmpdir:
# Put our bundled wheels into a temporary directory and construct the
# additional paths that need added to sys.path
additional_paths = []
@@ -105,10 +117,7 @@
if verbosity:
args += ["-" + "v" * verbosity]
- _run_pip(args + [p[0] for p in _PROJECTS], additional_paths)
- finally:
- shutil.rmtree(tmpdir, ignore_errors=True)
-
+ 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
@@ -135,7 +144,7 @@
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):
@@ -176,27 +185,20 @@
"--altinstall",
action="store_true",
default=False,
- help=("Make an alternate install, installing only the X.Y versioned"
- "scripts (Default: pipX, pipX.Y, easy_install-X.Y)"),
+ help=("Make an alternate install, installing only the X.Y versioned "
+ "scripts (Default: pipX, pipX.Y, easy_install-X.Y)."),
)
parser.add_argument(
"--default-pip",
action="store_true",
- default=True,
- dest="default_pip",
- help=argparse.SUPPRESS,
- )
- parser.add_argument(
- "--no-default-pip",
- action="store_false",
- dest="default_pip",
- help=("Make a non default install, installing only the X and X.Y "
- "versioned scripts."),
+ default=False,
+ help=("Make a default pip install, installing the unqualified pip "
+ "and easy_install in addition to the versioned scripts."),
)
args = parser.parse_args(argv)
- bootstrap(
+ return _bootstrap(
root=args.root,
upgrade=args.upgrade,
user=args.user,
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit