From 13bd2b74becf04ff85e187e8ed20d9ce67b1a9d5 Mon Sep 17 00:00:00 2001 From: "Mark E. Haase" Date: Mon, 25 Jul 2016 10:48:49 -0400 Subject: [PATCH] Fix issue 24875. Add --ignore-installed flag to ensurepip and use it when invoking from venv. --- Lib/ensurepip/__init__.py | 11 ++++++++++- Lib/venv/__init__.py | 3 ++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Lib/ensurepip/__init__.py b/Lib/ensurepip/__init__.py index 08aedf9..127dc67 100644 --- a/Lib/ensurepip/__init__.py +++ b/Lib/ensurepip/__init__.py @@ -61,7 +61,7 @@ def _disable_pip_configuration_settings(): def bootstrap(*, root=None, upgrade=False, user=False, altinstall=False, default_pip=False, - verbosity=0): + ignore_installed=False, verbosity=0): """ Bootstrap pip into the current Python installation (or the given root directory). @@ -112,6 +112,8 @@ def bootstrap(*, root=None, upgrade=False, user=False, args += ["--user"] if verbosity: args += ["-" + "v" * verbosity] + if ignore_installed: + args += ["--ignore-installed"] _run_pip(args + [p[0] for p in _PROJECTS], additional_paths) @@ -197,6 +199,12 @@ def _main(argv=None): help=("Make a default pip install, installing the unqualified pip " "and easy_install in addition to the versioned scripts"), ) + parser.add_argument( + "--ignore-installed", + action="store_true", + default=False, + help=("Ignore the installed packages (reinstalling instead)."), + ) args = parser.parse_args(argv) @@ -207,4 +215,5 @@ def _main(argv=None): verbosity=args.verbosity, altinstall=args.altinstall, default_pip=args.default_pip, + ignore_installed=args.ignore_installed ) diff --git a/Lib/venv/__init__.py b/Lib/venv/__init__.py index fa3d2a3..d2c58f5 100644 --- a/Lib/venv/__init__.py +++ b/Lib/venv/__init__.py @@ -229,7 +229,8 @@ class EnvBuilder: # environment vars, the current directory and anything else # intended for the global Python environment cmd = [context.env_exe, '-Im', 'ensurepip', '--upgrade', - '--default-pip'] + '--default-pip', + '--ignore-installed'] subprocess.check_output(cmd, stderr=subprocess.STDOUT) def setup_scripts(self, context): -- 2.7.4 (Apple Git-66)