diff options
author | Nick Coghlan <ncoghlan@gmail.com> | 2013-11-30 07:15:09 (GMT) |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2013-11-30 07:15:09 (GMT) |
commit | fdf3a620a27c6d924be62877befa3a5881de6a41 (patch) | |
tree | 1936b83a9bcad591f2b99951bf01143a0ba89583 /Lib/ensurepip/__init__.py | |
parent | 1b1b1789d022095266c83d4ce441ae6d096afbcd (diff) | |
download | cpython-fdf3a620a27c6d924be62877befa3a5881de6a41.zip cpython-fdf3a620a27c6d924be62877befa3a5881de6a41.tar.gz cpython-fdf3a620a27c6d924be62877befa3a5881de6a41.tar.bz2 |
Issue #19728: add private ensurepip._uninstall CLI
MvL would like to be able to preserve CPython's existing clean
uninstall behaviour on Windows before enabling the pip
installation option by default.
This private CLI means running "python -m ensurepip._uninstall"
will remove pip and setuptools before proceeding with the rest
of the uninstallation process.
If the version of pip differs from the one bootstrapped by
CPython, then the uninstallation helper will leave it alone
(just like any other pip installed packages)
Diffstat (limited to 'Lib/ensurepip/__init__.py')
-rw-r--r-- | Lib/ensurepip/__init__.py | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/Lib/ensurepip/__init__.py b/Lib/ensurepip/__init__.py index 1a644da..63013ae 100644 --- a/Lib/ensurepip/__init__.py +++ b/Lib/ensurepip/__init__.py @@ -20,9 +20,10 @@ _PROJECTS = [ ] -def _run_pip(args, additional_paths): +def _run_pip(args, additional_paths=None): # Add our bundled software to the sys.path so we can import it - sys.path = additional_paths + sys.path + if additional_paths is not None: + sys.path = additional_paths + sys.path # Install the bundled software import pip @@ -90,3 +91,24 @@ def bootstrap(*, root=None, upgrade=False, user=False, args += ["-" + "v" * verbosity] _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""" + # Nothing to do if pip was never installed, or has been removed + try: + import pip + except ImportError: + return + + # If the pip version doesn't match the bundled one, leave it alone + if pip.__version__ != _PIP_VERSION: + msg = ("ensurepip will only uninstall a matching pip " + "({!r} installed, {!r} bundled)") + raise RuntimeError(msg.format(pip.__version__, _PIP_VERSION)) + + # Construct the arguments to be passed to the pip command + args = ["uninstall", "-y"] + if verbosity: + args += ["-" + "v" * verbosity] + + _run_pip(args + [p[0] for p in reversed(_PROJECTS)]) |