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

fix: Reintroduce the uninstall command #3650

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions micromamba/src/umamba.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ set_umamba_command(CLI::App* com, mamba::Configuration& config)

CLI::App* remove_subcom = com->add_subcommand("remove", "Remove packages from active environment");
set_remove_command(remove_subcom, config);
remove_subcom->alias("uninstall");

CLI::App* list_subcom = com->add_subcommand("list", "List packages in active environment");
set_list_command(list_subcom, config);
Expand Down
22 changes: 22 additions & 0 deletions micromamba/tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,28 @@ def remove(*args, no_dry_run=False, **kwargs):
raise (e)


def uninstall(*args, no_dry_run=False, **kwargs):
umamba = get_umamba()
cmd = [umamba, "uninstall", "-y"] + [arg for arg in args if arg]

if "--print-config-only" in args:
cmd += ["--debug"]
if (dry_run_tests == DryRun.DRY) and "--dry-run" not in args and not no_dry_run:
cmd += ["--dry-run"]

try:
res = subprocess_run(*cmd, **kwargs)
if "--json" in args:
j = json.loads(res)
return j
if "--print-config-only" in args:
return yaml.load(res, Loader=yaml.FullLoader)
return res.decode()
except subprocess.CalledProcessError as e:
print(f"Error when executing '{' '.join(cmd)}'")
raise (e)


def clean(*args, no_dry_run=False, **kwargs):
umamba = get_umamba()
cmd = [umamba, "clean", "-y"] + [arg for arg in args if arg]
Expand Down
37 changes: 37 additions & 0 deletions micromamba/tests/test_remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,40 @@ def test_remove_config_target_prefix(
else:
res = helpers.remove(*cmd, "--print-config-only")
remove_config_common_assertions(res, root_prefix=r, target_prefix=p)


def test_uninstall(tmp_home, tmp_root_prefix, tmp_xtensor_env, tmp_env_name):
# Install xtensor and then uninstall xtensor the first time with the `remove`
# subcommand and a second time with the `uninstall` subcommand and check that
# their outputs are the same and that the environment is in the same state
helpers.create("-n", tmp_env_name, "--json", no_dry_run=True)

res_list = helpers.umamba_list("-n", tmp_env_name, "--json")
n_packages_after_init = len(res_list)

# Install xtensor
helpers.install("xtensor", "-n", tmp_env_name, no_dry_run=True)

# Remove xtensor
res_remove = helpers.remove("xtensor", "-n", tmp_env_name, "--json")
assert res_remove["success"]
assert res_remove["actions"]["PREFIX"] == str(tmp_xtensor_env)

# Check that the environment does not contain any packages
res_list = helpers.umamba_list("-n", tmp_env_name, "--json")
assert len(res_list) == n_packages_after_init

# Reinstall xtensor
helpers.install("xtensor", "-n", tmp_env_name, no_dry_run=True)

# Uninstall xtensor
res_uninstall = helpers.uninstall("xtensor", "-n", tmp_env_name, "--json")
assert res_uninstall["success"]
assert res_uninstall["actions"]["PREFIX"] == str(tmp_xtensor_env)

# Check that the environment does not contain any packages
res_list = helpers.umamba_list("-n", tmp_env_name, "--json")
assert len(res_list) == n_packages_after_init

# Check that the outputs of the `remove` and `uninstall` subcommands are the same
assert res_remove == res_uninstall
Loading