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

feat: add md5 flag to list command #3773

Merged
merged 2 commits into from
Jan 28, 2025
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
14 changes: 12 additions & 2 deletions libmamba/src/api/list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ namespace mamba
bool no_pip;
bool reverse;
bool explicit_;
bool md5;
};

struct formatted_pkg
{
std::string name, version, build, channel, url;
std::string name, version, build, channel, url, md5;
};

bool compare_alphabetically(const formatted_pkg& a, const formatted_pkg& b)
Expand Down Expand Up @@ -199,6 +200,7 @@ namespace mamba
formatted_pkgs.version = package.second.version;
formatted_pkgs.build = package.second.build_string;
formatted_pkgs.url = package.second.package_url;
formatted_pkgs.md5 = package.second.md5;
packages.push_back(formatted_pkgs);
}
}
Expand All @@ -212,7 +214,14 @@ namespace mamba
{
for (auto p : packages)
{
std::cout << p.url << std::endl;
if (options.md5)
{
std::cout << p.url << "#" << p.md5 << std::endl;
}
else
{
std::cout << p.url << std::endl;
}
}
}
else
Expand Down Expand Up @@ -258,6 +267,7 @@ namespace mamba
options.no_pip = config.at("no_pip").value<bool>();
options.reverse = config.at("reverse").value<bool>();
options.explicit_ = config.at("explicit").value<bool>();
options.md5 = config.at("md5").value<bool>();

auto channel_context = ChannelContext::make_conda_compatible(config.context());
detail::list_packages(config.context(), regex, channel_context, std::move(options));
Expand Down
5 changes: 5 additions & 0 deletions micromamba/src/list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ init_list_parser(CLI::App* subcom, Configuration& config)
));
subcom->add_flag("--explicit", explicit_.get_cli_config<bool>(), explicit_.description());

auto& md5 = config.insert(
Configurable("md5", false).group("cli").description("Add MD5 hashsum when using --explicit")
);
subcom->add_flag("--md5", md5.get_cli_config<bool>(), md5.description());


// TODO: implement this in libmamba/list.cpp
/*auto& canonical = config.insert(Configurable("canonical", false)
Expand Down
2 changes: 1 addition & 1 deletion micromamba/tests/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -1675,6 +1675,7 @@ def test_glob_in_build_string(monkeypatch, tmp_path):
for package in out["actions"]["FETCH"]
)


def test_non_url_encoding(tmp_path):
# Non-regression test for https://github.com/mamba-org/mamba/issues/3737
env_prefix = tmp_path / "env-non_url_encoding"
Expand All @@ -1692,4 +1693,3 @@ def test_non_url_encoding(tmp_path):
non_encoded_url_start = "https://conda.anaconda.org/conda-forge/linux-64/x264-1!"
out = helpers.run_env("export", "-p", env_prefix, "--explicit")
assert non_encoded_url_start in out

21 changes: 13 additions & 8 deletions micromamba/tests/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,27 @@ def test_list_no_json(


@pytest.mark.parametrize("explicit_flag", ["", "--explicit"])
@pytest.mark.parametrize("md5_flag", ["", "--md5"])
@pytest.mark.parametrize("env_selector", ["", "name", "prefix"])
@pytest.mark.parametrize("shared_pkgs_dirs", [True], indirect=True)
def test_list_explicit_no_json(
tmp_home, tmp_root_prefix, tmp_env_name, tmp_xtensor_env, env_selector, explicit_flag
def test_list_explicit(
tmp_home, tmp_root_prefix, tmp_env_name, tmp_xtensor_env, env_selector, explicit_flag, md5_flag
):
if env_selector == "prefix":
res = helpers.umamba_list("-p", tmp_xtensor_env, explicit_flag)
res = helpers.umamba_list("-p", tmp_xtensor_env, explicit_flag, md5_flag)
elif env_selector == "name":
res = helpers.umamba_list("-n", tmp_env_name, explicit_flag)
res = helpers.umamba_list("-n", tmp_env_name, explicit_flag, md5_flag)
else:
res = helpers.umamba_list(explicit_flag)
res = helpers.umamba_list(explicit_flag, md5_flag)

packages_url_list = res.strip().split("\n")[2:]
outputs_list = res.strip().split("\n")[2:]
if explicit_flag == "--explicit":
for url in packages_url_list:
assert "conda-forge" in url
for output in outputs_list:
assert "/conda-forge/" in output
if md5_flag == "--md5":
assert "#" in output
else:
assert "#" not in output


@pytest.mark.parametrize("quiet_flag", ["", "-q", "--quiet"])
Expand Down
Loading