diff options
author | Nick Coghlan <ncoghlan@gmail.com> | 2013-12-23 07:39:12 (GMT) |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2013-12-23 07:39:12 (GMT) |
commit | ed9af52ff064663f8ed2f40191b144a2b6a9865b (patch) | |
tree | 9ee2f95c0e453e14283c85e157d1d8445e67bb85 /Lib/ensurepip | |
parent | 6256fcbc97e0b1a1e0df1972221232b3a78dff18 (diff) | |
download | cpython-ed9af52ff064663f8ed2f40191b144a2b6a9865b.zip cpython-ed9af52ff064663f8ed2f40191b144a2b6a9865b.tar.gz cpython-ed9af52ff064663f8ed2f40191b144a2b6a9865b.tar.bz2 |
Issue #19734: ignore pip env vars in ensurepip._uninstall
Diffstat (limited to 'Lib/ensurepip')
-rw-r--r-- | Lib/ensurepip/__init__.py | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/Lib/ensurepip/__init__.py b/Lib/ensurepip/__init__.py index 5ceda51..090c410 100644 --- a/Lib/ensurepip/__init__.py +++ b/Lib/ensurepip/__init__.py @@ -36,6 +36,14 @@ def version(): """ return _PIP_VERSION +def _clear_pip_environment_variables(): + # We deliberately ignore all pip environment variables + # when invoking pip + # See http://bugs.python.org/issue19734 for details + keys_to_remove = [k for k in os.environ if k.startswith("PIP_")] + for k in keys_to_remove: + del os.environ[k] + def bootstrap(*, root=None, upgrade=False, user=False, altinstall=False, default_pip=False, @@ -49,11 +57,7 @@ def bootstrap(*, root=None, upgrade=False, user=False, if altinstall and default_pip: raise ValueError("Cannot use altinstall and default_pip together") - # We deliberately ignore all pip environment variables - # See http://bugs.python.org/issue19734 for details - keys_to_remove = [k for k in os.environ if k.startswith("PIP_")] - for k in keys_to_remove: - del os.environ[k] + _clear_pip_environment_variables() # By default, installing pip and setuptools installs all of the # following scripts (X.Y == running Python version): @@ -101,7 +105,10 @@ def bootstrap(*, root=None, upgrade=False, user=False, _run_pip(args + [p[0] for p in _PROJECTS], additional_paths) def _uninstall(*, verbosity=0): - """Helper to support a clean default uninstall process on Windows""" + """Helper to support a clean default uninstall process on Windows + + Note that calling this function may alter os.environ. + """ # Nothing to do if pip was never installed, or has been removed try: import pip @@ -114,6 +121,8 @@ def _uninstall(*, verbosity=0): "({!r} installed, {!r} bundled)") raise RuntimeError(msg.format(pip.__version__, _PIP_VERSION)) + _clear_pip_environment_variables() + # Construct the arguments to be passed to the pip command args = ["uninstall", "-y"] if verbosity: |