OCI/Conda mapping (#3310)

* Map packages names starting with '_' to match OCI registries rules (and CEP 70)

* Use _go_select instead of _libgcc_mutex in tests
Remove dry-run and check result with umamba_list
This commit is contained in:
Hind-M 2024-06-13 09:38:24 +02:00 committed by GitHub
parent 7f8d5649c0
commit 287bf22de2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 97 additions and 10 deletions

View File

@ -309,13 +309,25 @@ namespace mamba::download
std::string OCIMirror::get_repo(const std::string& repo) const
{
// OCI image names cannot start with `_`
// Get the package name and prepend with `zzz` to map to `channel_mirrors` implementation
auto parts = util::rsplit(repo, "/", 1);
assert(parts.size() == 2);
std::string mapped_package_name = parts.back();
std::string mapped_repo = repo;
if (util::starts_with(mapped_package_name, "_"))
{
mapped_package_name.insert(0, std::string("zzz"));
mapped_repo = fmt::format("{}/{}", parts[0], mapped_package_name);
}
if (!m_repo_prefix.empty())
{
return fmt::format("{}/{}", m_repo_prefix, repo);
return fmt::format("{}/{}", m_repo_prefix, mapped_repo);
}
else
{
return repo;
return mapped_repo;
}
}

View File

@ -1186,7 +1186,7 @@ oci_registry_config = {
@pytest.mark.parametrize("shared_pkgs_dirs", [True], indirect=True)
@pytest.mark.parametrize("spec", ["pandoc", "pandoc=3.1.13"])
@pytest.mark.parametrize("parser", ["mamba", "libsolv"])
def test_create_with_oci_mirrored_channels(tmp_home, tmp_root_prefix, tmp_path, spec, parser):
def test_create_from_oci_mirrored_channels(tmp_home, tmp_root_prefix, tmp_path, spec, parser):
env_name = "myenv"
env_prefix = tmp_root_prefix / "envs" / env_name
@ -1203,15 +1203,90 @@ def test_create_with_oci_mirrored_channels(tmp_home, tmp_root_prefix, tmp_path,
default_channel=False,
no_rc=False,
)
assert res["success"]
assert res["actions"]["PREFIX"] == str(env_prefix)
for pkg in res["actions"]["LINK"]:
assert pkg["url"].startswith(
"https://pkg-containers.githubusercontent.com/ghcr1/blobs/pandoc"
packages = helpers.umamba_list("-p", env_prefix, "--json")
assert len(packages) == 1
pkg = packages[0]
assert pkg["name"] == "pandoc"
if spec == "pandoc=3.1.13":
assert pkg["version"] == "3.1.13"
assert pkg["base_url"].startswith(
"https://pkg-containers.githubusercontent.com/ghcr1/blobs/pandoc"
)
@pytest.mark.parametrize("shared_pkgs_dirs", [True], indirect=True)
@pytest.mark.parametrize("parser", ["mamba", "libsolv"])
def test_create_from_oci_mirrored_channels_with_deps(tmp_home, tmp_root_prefix, tmp_path, parser):
env_name = "myenv"
env_prefix = tmp_root_prefix / "envs" / env_name
rc_file = tmp_path / "config.yaml"
rc_file.write_text(yaml.dump(oci_registry_config))
cmd = ["-n", env_name, "xtensor", "--json", "-c", "oci_channel"]
if parser == "libsolv":
cmd += ["--no-exp-repodata-parsing"]
res = helpers.create(
*cmd,
f"--rc-file={rc_file}",
default_channel=False,
no_rc=False,
)
assert res["success"]
packages = helpers.umamba_list("-p", env_prefix, "--json")
assert len(packages) > 2
assert any(
package["name"] == "xtensor"
and package["base_url"].startswith(
"https://pkg-containers.githubusercontent.com/ghcr1/blobs/xtensor"
)
assert pkg["name"] == "pandoc"
if spec == "pandoc=3.1.13":
assert pkg["version"] == "3.1.13"
for package in packages
)
assert any(
package["name"] == "xtl"
and package["base_url"].startswith(
"https://pkg-containers.githubusercontent.com/ghcr1/blobs/xtl"
)
for package in packages
)
@pytest.mark.parametrize("shared_pkgs_dirs", [True], indirect=True)
@pytest.mark.parametrize("parser", ["mamba", "libsolv"])
def test_create_from_oci_mirrored_channels_pkg_name_mapping(
tmp_home, tmp_root_prefix, tmp_path, parser
):
# This is to test Conda/OCI package name mapping
# Test fetching package from OCI registry with name starting with '_'
env_name = "myenv"
env_prefix = tmp_root_prefix / "envs" / env_name
rc_file = tmp_path / "config.yaml"
rc_file.write_text(yaml.dump(oci_registry_config))
cmd = ["-n", env_name, "_go_select", "--json", "-c", "oci_channel"]
if parser == "libsolv":
cmd += ["--no-exp-repodata-parsing"]
res = helpers.create(
*cmd,
f"--rc-file={rc_file}",
default_channel=False,
no_rc=False,
)
assert res["success"]
packages = helpers.umamba_list("-p", env_prefix, "--json")
assert len(packages) == 1
pkg = packages[0]
assert pkg["name"] == "_go_select"
assert pkg["base_url"].startswith(
"https://pkg-containers.githubusercontent.com/ghcr1/blobs/_go_select"
)
@pytest.mark.parametrize("shared_pkgs_dirs", [True], indirect=True)