Helper to support a clean default uninstall process on Windows Note that calling this function may alter os.environ.
(*, verbosity=0)
| 173 | |
| 174 | |
| 175 | def _uninstall_helper(*, verbosity=0): |
| 176 | """Helper to support a clean default uninstall process on Windows |
| 177 | |
| 178 | Note that calling this function may alter os.environ. |
| 179 | """ |
| 180 | # Nothing to do if pip was never installed, or has been removed |
| 181 | try: |
| 182 | import pip |
| 183 | except ImportError: |
| 184 | return |
| 185 | |
| 186 | # If the installed pip version doesn't match the available one, |
| 187 | # leave it alone |
| 188 | available_version = version() |
| 189 | if pip.__version__ != available_version: |
| 190 | print(f"ensurepip will only uninstall a matching version " |
| 191 | f"({pip.__version__!r} installed, " |
| 192 | f"{available_version!r} available)", |
| 193 | file=sys.stderr) |
| 194 | return |
| 195 | |
| 196 | _disable_pip_configuration_settings() |
| 197 | |
| 198 | # Construct the arguments to be passed to the pip command |
| 199 | args = ["uninstall", "-y", "--disable-pip-version-check"] |
| 200 | if verbosity: |
| 201 | args += ["-" + "v" * verbosity] |
| 202 | |
| 203 | return _run_pip([*args, "pip"]) |
| 204 | |
| 205 | |
| 206 | def _main(argv=None): |
nothing calls this directly
no test coverage detected