Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] refactor mim uninstall #135

Merged
merged 15 commits into from Jun 24, 2022
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
59 changes: 50 additions & 9 deletions mim/commands/uninstall.py
@@ -1,39 +1,80 @@
# Copyright (c) OpenMMLab. All rights reserved.
from typing import Any, List, Tuple, Union

import click

from mim.click import argument, get_installed_package, param2lowercase
from mim.utils import call_command


@click.command('uninstall')
@click.command(
'uninstall',
context_settings=dict(ignore_unknown_options=True),
)
@argument(
'package', autocompletion=get_installed_package, callback=param2lowercase)
'args',
autocompletion=get_installed_package,
callback=param2lowercase,
nargs=-1,
type=click.UNPROCESSED)
@click.option(
'-y',
'--yes',
'confirm_yes',
is_flag=True,
help='Don’t ask for confirmation of uninstall deletions.')
def cli(package: str, confirm_yes: bool) -> None:
@click.option(
'-r',
'--requirement',
'requirements',
multiple=True,
help='Uninstall all the packages listed in the given requirements '
'file. This option can be used multiple times.')
ice-tong marked this conversation as resolved.
Show resolved Hide resolved
def cli(args: Tuple,
confirm_yes: bool = False,
requirements: Tuple = ()) -> None:
"""Uninstall package.

Same as `pip uninstall`.

\b
Example:

> mim uninstall mmcv-full
> mim uninstall -y mmcv-full
> mim uninstall mmdet mmcls

Here we list several commonly used options.

For more options, please refer to `pip uninstall --help`.
"""
uninstall(package, confirm_yes)
exit_code = uninstall(list(args), confirm_yes, requirements)
exit(exit_code)


def uninstall(package: str, confirm_yes=False) -> None:
def uninstall(uninstall_args: Union[str, List],
confirm_yes: bool = True,
requirements: Tuple = ()) -> Any:
"""Uninstall package.

Args:
package (str): The name of uninstalled package, such as mmcv-full.
uninstall_args (str or list): A package name or a list of package names
to uninstalled. You can also put some `pip uninstal` options here.
confirm_yes (bool): Don’t ask for confirmation of uninstall deletions.
Default: True.
requirements (tuple): A tuple of requirements files to uninstalled.

Returns:
The status code return by `pip uninstall`.
ice-tong marked this conversation as resolved.
Show resolved Hide resolved
"""
uninstall_cmd = ['python', '-m', 'pip', 'uninstall', package]
if type(uninstall_args) is str:
zhouzaida marked this conversation as resolved.
Show resolved Hide resolved
uninstall_args = [uninstall_args]

if confirm_yes:
uninstall_cmd.append('-y')
uninstall_args.append('-y') # type: ignore

for requirement_file in requirements:
uninstall_args += ['-r', requirement_file] # type: ignore

call_command(uninstall_cmd)
pip_uninstall_cmd = ['python', '-m', 'pip', 'uninstall']
return call_command(pip_uninstall_cmd + uninstall_args) # type: ignore