From fdf3a620a27c6d924be62877befa3a5881de6a41 Mon Sep 17 00:00:00 2001 From: Nick Coghlan Date: Sat, 30 Nov 2013 17:15:09 +1000 Subject: 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) --- Lib/ensurepip/__init__.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'Lib/ensurepip') diff --git a/Lib/ensurepip/__init__.py b/Lib/ensurepip/__init__.py index 1a644da634..63013aec3d 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)]) -- cgit v1.2.1