From af3698594a84132e87deff337e20ae1bf1c9fe06 Mon Sep 17 00:00:00 2001 From: Sandrine Pataut Date: Tue, 21 Jan 2025 17:23:04 +0100 Subject: [PATCH 1/5] add canonical subcommand --- libmamba/src/api/list.cpp | 16 +++++++++++++--- micromamba/src/list.cpp | 6 ++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/libmamba/src/api/list.cpp b/libmamba/src/api/list.cpp index caab6e3dad..7a3eafa921 100644 --- a/libmamba/src/api/list.cpp +++ b/libmamba/src/api/list.cpp @@ -27,11 +27,12 @@ namespace mamba bool reverse; bool explicit_; bool md5; + bool canonical; }; struct formatted_pkg { - std::string name, version, build, channel, url, md5; + std::string name, version, build, channel, url, md5, build_string; }; bool compare_alphabetically(const formatted_pkg& a, const formatted_pkg& b) @@ -201,6 +202,7 @@ namespace mamba formatted_pkgs.build = package.second.build_string; formatted_pkgs.url = package.second.package_url; formatted_pkgs.md5 = package.second.md5; + formatted_pkgs.build_string = package.second.build_string; packages.push_back(formatted_pkgs); } } @@ -209,8 +211,15 @@ namespace mamba : compare_alphabetically; std::sort(packages.begin(), packages.end(), comparator); - // format and print table - if (options.explicit_) + // format and print output + if (options.canonical) + { + for (auto p : packages) + { + std::cout << p.name << "-" << p.version << "-" << p.build_string << std::endl; + } + } + else if (options.explicit_) { for (auto p : packages) { @@ -268,6 +277,7 @@ namespace mamba options.reverse = config.at("reverse").value(); options.explicit_ = config.at("explicit").value(); options.md5 = config.at("md5").value(); + options.canonical = config.at("canonical").value(); auto channel_context = ChannelContext::make_conda_compatible(config.context()); detail::list_packages(config.context(), regex, channel_context, std::move(options)); diff --git a/micromamba/src/list.cpp b/micromamba/src/list.cpp index 5d6776f7ec..f6184a5d5c 100644 --- a/micromamba/src/list.cpp +++ b/micromamba/src/list.cpp @@ -50,12 +50,10 @@ init_list_parser(CLI::App* subcom, Configuration& config) ); subcom->add_flag("--md5", md5.get_cli_config(), md5.description()); - - // TODO: implement this in libmamba/list.cpp - /*auto& canonical = config.insert(Configurable("canonical", false) + auto& canonical = config.insert(Configurable("canonical", false) .group("cli") .description("Output canonical names of packages only.")); - subcom->add_flag("-c,--canonical", canonical.get_cli_config(), canonical.description());*/ + subcom->add_flag("-c,--canonical", canonical.get_cli_config(), canonical.description()); } void From b617d6e9a85c03c99c961189b62604ae4aee0661 Mon Sep 17 00:00:00 2001 From: Sandrine Pataut Date: Tue, 28 Jan 2025 15:56:16 +0100 Subject: [PATCH 2/5] add canonical test --- micromamba/tests/test_list.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/micromamba/tests/test_list.py b/micromamba/tests/test_list.py index b4530e107f..20cbd191d3 100644 --- a/micromamba/tests/test_list.py +++ b/micromamba/tests/test_list.py @@ -103,6 +103,26 @@ def test_list_explicit( assert "#" not in output +@pytest.mark.parametrize("canonical_flag", ["", "--canonical"]) +@pytest.mark.parametrize("env_selector", ["", "name", "prefix"]) +@pytest.mark.parametrize("shared_pkgs_dirs", [True], indirect=True) +def test_list_canonical( + tmp_home, tmp_root_prefix, tmp_env_name, tmp_xtensor_env, env_selector, canonical_flag +): + if env_selector == "prefix": + res = helpers.umamba_list("-p", tmp_xtensor_env, canonical_flag) + elif env_selector == "name": + res = helpers.umamba_list("-n", tmp_env_name, canonical_flag) + else: + res = helpers.umamba_list(canonical_flag) + + outputs_list = res.strip().split("\n")[2:] + if canonical_flag == "--canonical": + items = ["conda-forge", "/", " "] + for output in outputs_list: + assert all(i not in output for i in items) + + @pytest.mark.parametrize("quiet_flag", ["", "-q", "--quiet"]) @pytest.mark.parametrize("shared_pkgs_dirs", [True], indirect=True) def test_list_name(tmp_home, tmp_root_prefix, tmp_xtensor_env, quiet_flag): From ab09b315ec89f2e34a1c6086754d008bda5ed97a Mon Sep 17 00:00:00 2001 From: Sandrine Pataut Date: Wed, 29 Jan 2025 15:34:26 +0100 Subject: [PATCH 3/5] change options priority --- libmamba/src/api/list.cpp | 34 +++++++++++++++++++++------------- micromamba/src/list.cpp | 8 +++++--- micromamba/tests/test_list.py | 5 +++-- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/libmamba/src/api/list.cpp b/libmamba/src/api/list.cpp index 7a3eafa921..89f939e4f2 100644 --- a/libmamba/src/api/list.cpp +++ b/libmamba/src/api/list.cpp @@ -22,17 +22,17 @@ namespace mamba { struct list_options { - bool full_name; - bool no_pip; - bool reverse; - bool explicit_; - bool md5; - bool canonical; + bool full_name = false; + bool no_pip = false; + bool reverse = false; + bool explicit_ = false; + bool md5 = false; + bool canonical = false; }; struct formatted_pkg { - std::string name, version, build, channel, url, md5, build_string; + std::string name, version, build, channel, url, md5, build_string, platform; }; bool compare_alphabetically(const formatted_pkg& a, const formatted_pkg& b) @@ -169,6 +169,7 @@ namespace mamba obj["channel"] = get_formatted_channel(pkg_info, channels.front()); obj["base_url"] = get_base_url(pkg_info, channels.front()); obj["url"] = pkg_info.package_url; + obj["md5"] = pkg_info.md5; obj["build_number"] = pkg_info.build_number; obj["build_string"] = pkg_info.build_string; obj["dist_name"] = pkg_info.str(); @@ -203,6 +204,7 @@ namespace mamba formatted_pkgs.url = package.second.package_url; formatted_pkgs.md5 = package.second.md5; formatted_pkgs.build_string = package.second.build_string; + formatted_pkgs.platform = package.second.platform; packages.push_back(formatted_pkgs); } } @@ -212,15 +214,13 @@ namespace mamba std::sort(packages.begin(), packages.end(), comparator); // format and print output - if (options.canonical) + if (options.explicit_) { - for (auto p : packages) + if (options.canonical) { - std::cout << p.name << "-" << p.version << "-" << p.build_string << std::endl; + std::cout << "Warning: Option --canonical ignored because of --explicit \n" + << std::endl; } - } - else if (options.explicit_) - { for (auto p : packages) { if (options.md5) @@ -233,6 +233,14 @@ namespace mamba } } } + else if (options.canonical) + { + for (auto p : packages) + { + std::cout << p.channel << "/" << p.platform << "::" << p.name << "-" + << p.version << "-" << p.build_string << std::endl; + } + } else { auto requested_specs = prefix_data.history().get_requested_specs_map(); diff --git a/micromamba/src/list.cpp b/micromamba/src/list.cpp index f6184a5d5c..9a68ac4aed 100644 --- a/micromamba/src/list.cpp +++ b/micromamba/src/list.cpp @@ -50,9 +50,11 @@ init_list_parser(CLI::App* subcom, Configuration& config) ); subcom->add_flag("--md5", md5.get_cli_config(), md5.description()); - auto& canonical = config.insert(Configurable("canonical", false) - .group("cli") - .description("Output canonical names of packages only.")); + auto& canonical = config.insert( + Configurable("canonical", false) + .group("cli") + .description("Output canonical names of packages only. Ignored if --explicit.") + ); subcom->add_flag("-c,--canonical", canonical.get_cli_config(), canonical.description()); } diff --git a/micromamba/tests/test_list.py b/micromamba/tests/test_list.py index 20cbd191d3..c6f955d861 100644 --- a/micromamba/tests/test_list.py +++ b/micromamba/tests/test_list.py @@ -118,9 +118,10 @@ def test_list_canonical( outputs_list = res.strip().split("\n")[2:] if canonical_flag == "--canonical": - items = ["conda-forge", "/", " "] + items = ["conda-forge/", "::"] for output in outputs_list: - assert all(i not in output for i in items) + assert all(i in output for i in items) + assert " " not in output @pytest.mark.parametrize("quiet_flag", ["", "-q", "--quiet"]) From a517446d544a66d4ff337612dd7944d7d22af1ec Mon Sep 17 00:00:00 2001 From: Sandrine Pataut Date: Wed, 29 Jan 2025 18:43:48 +0100 Subject: [PATCH 4/5] update test --- libmamba/src/api/list.cpp | 4 ++-- micromamba/tests/test_list.py | 43 +++++++++++++++-------------------- 2 files changed, 20 insertions(+), 27 deletions(-) diff --git a/libmamba/src/api/list.cpp b/libmamba/src/api/list.cpp index 89f939e4f2..1539bc817a 100644 --- a/libmamba/src/api/list.cpp +++ b/libmamba/src/api/list.cpp @@ -218,8 +218,8 @@ namespace mamba { if (options.canonical) { - std::cout << "Warning: Option --canonical ignored because of --explicit \n" - << std::endl; + LOG_WARNING << "Warning: Option --canonical ignored because of --explicit" + << std::endl; } for (auto p : packages) { diff --git a/micromamba/tests/test_list.py b/micromamba/tests/test_list.py index c6f955d861..4550ca98db 100644 --- a/micromamba/tests/test_list.py +++ b/micromamba/tests/test_list.py @@ -81,17 +81,25 @@ def test_list_no_json( @pytest.mark.parametrize("explicit_flag", ["", "--explicit"]) @pytest.mark.parametrize("md5_flag", ["", "--md5"]) +@pytest.mark.parametrize("canonical_flag", ["", "-c", "--canonical"]) @pytest.mark.parametrize("env_selector", ["", "name", "prefix"]) @pytest.mark.parametrize("shared_pkgs_dirs", [True], indirect=True) -def test_list_explicit( - tmp_home, tmp_root_prefix, tmp_env_name, tmp_xtensor_env, env_selector, explicit_flag, md5_flag +def test_list_subcommands( + tmp_home, + tmp_root_prefix, + tmp_env_name, + tmp_xtensor_env, + env_selector, + explicit_flag, + md5_flag, + canonical_flag, ): if env_selector == "prefix": - res = helpers.umamba_list("-p", tmp_xtensor_env, explicit_flag, md5_flag) + res = helpers.umamba_list("-p", tmp_xtensor_env, explicit_flag, md5_flag, canonical_flag) elif env_selector == "name": - res = helpers.umamba_list("-n", tmp_env_name, explicit_flag, md5_flag) + res = helpers.umamba_list("-n", tmp_env_name, explicit_flag, md5_flag, canonical_flag) else: - res = helpers.umamba_list(explicit_flag, md5_flag) + res = helpers.umamba_list(explicit_flag, md5_flag, canonical_flag) outputs_list = res.strip().split("\n")[2:] if explicit_flag == "--explicit": @@ -101,27 +109,12 @@ def test_list_explicit( assert "#" in output else: assert "#" not in output - - -@pytest.mark.parametrize("canonical_flag", ["", "--canonical"]) -@pytest.mark.parametrize("env_selector", ["", "name", "prefix"]) -@pytest.mark.parametrize("shared_pkgs_dirs", [True], indirect=True) -def test_list_canonical( - tmp_home, tmp_root_prefix, tmp_env_name, tmp_xtensor_env, env_selector, canonical_flag -): - if env_selector == "prefix": - res = helpers.umamba_list("-p", tmp_xtensor_env, canonical_flag) - elif env_selector == "name": - res = helpers.umamba_list("-n", tmp_env_name, canonical_flag) else: - res = helpers.umamba_list(canonical_flag) - - outputs_list = res.strip().split("\n")[2:] - if canonical_flag == "--canonical": - items = ["conda-forge/", "::"] - for output in outputs_list: - assert all(i in output for i in items) - assert " " not in output + if canonical_flag == "--canonical": + items = ["conda-forge/", "::"] + for output in outputs_list: + assert all(i in output for i in items) + assert " " not in output @pytest.mark.parametrize("quiet_flag", ["", "-q", "--quiet"]) From 5339a38057f0f027c336053592efc92a691f8ab0 Mon Sep 17 00:00:00 2001 From: Sandrine Pataut Date: Fri, 31 Jan 2025 12:25:36 +0100 Subject: [PATCH 5/5] edit warning --- libmamba/src/api/list.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libmamba/src/api/list.cpp b/libmamba/src/api/list.cpp index 1539bc817a..cfc689c209 100644 --- a/libmamba/src/api/list.cpp +++ b/libmamba/src/api/list.cpp @@ -218,8 +218,7 @@ namespace mamba { if (options.canonical) { - LOG_WARNING << "Warning: Option --canonical ignored because of --explicit" - << std::endl; + LOG_WARNING << "Option --canonical ignored because of --explicit"; } for (auto p : packages) {