From aa71ff98a3b88a205364715f0d1f3954d8ae47ff Mon Sep 17 00:00:00 2001 From: Julien Jerphanion Date: Tue, 3 Dec 2024 14:16:29 +0100 Subject: [PATCH 1/2] fix: Reintroduce the uninstall command Signed-off-by: Julien Jerphanion --- micromamba/src/umamba.cpp | 7 +++++++ micromamba/tests/helpers.py | 22 ++++++++++++++++++++ micromamba/tests/test_remove.py | 37 +++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+) diff --git a/micromamba/src/umamba.cpp b/micromamba/src/umamba.cpp index 73268e2725..4280ea8048 100644 --- a/micromamba/src/umamba.cpp +++ b/micromamba/src/umamba.cpp @@ -63,6 +63,13 @@ 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); + // `uninstall` is an alias for `remove` + CLI::App* uninstall_subcom = com->add_subcommand( + "uninstall", + "Remove packages from active environment" + ); + set_remove_command(uninstall_subcom, config); + CLI::App* list_subcom = com->add_subcommand("list", "List packages in active environment"); set_list_command(list_subcom, config); diff --git a/micromamba/tests/helpers.py b/micromamba/tests/helpers.py index 51621345bf..708dbd8ce8 100644 --- a/micromamba/tests/helpers.py +++ b/micromamba/tests/helpers.py @@ -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] diff --git a/micromamba/tests/test_remove.py b/micromamba/tests/test_remove.py index fe710d5d50..a8f159f8c5 100644 --- a/micromamba/tests/test_remove.py +++ b/micromamba/tests/test_remove.py @@ -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 From fb3c0ca9b90f24666b23b046e4c871381e08ccea Mon Sep 17 00:00:00 2001 From: Julien Jerphanion Date: Wed, 4 Dec 2024 11:07:24 +0100 Subject: [PATCH 2/2] Simply add a subcommand Signed-off-by: Julien Jerphanion --- micromamba/src/umamba.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/micromamba/src/umamba.cpp b/micromamba/src/umamba.cpp index 4280ea8048..5d9c02d13f 100644 --- a/micromamba/src/umamba.cpp +++ b/micromamba/src/umamba.cpp @@ -62,13 +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); - - // `uninstall` is an alias for `remove` - CLI::App* uninstall_subcom = com->add_subcommand( - "uninstall", - "Remove packages from active environment" - ); - set_remove_command(uninstall_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);