mirror of https://github.com/mamba-org/mamba.git
fix: Reintroduce the `uninstall` command (#3650)
Signed-off-by: Julien Jerphanion <git@jjerphan.xyz>
This commit is contained in:
parent
a85eb16149
commit
575809fbc3
|
@ -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);
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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…
Reference in New Issue