diff --git a/libmamba/include/mamba/core/virtual_packages.hpp b/libmamba/include/mamba/core/virtual_packages.hpp index 4a92c65320..6111e6a347 100644 --- a/libmamba/include/mamba/core/virtual_packages.hpp +++ b/libmamba/include/mamba/core/virtual_packages.hpp @@ -16,12 +16,11 @@ namespace mamba { class Context; - std::vector get_virtual_packages(const Context& context); + std::vector get_virtual_packages(const std::string& platform); namespace detail { std::string cuda_version(); - std::string get_arch(); auto make_virtual_package( std::string name, @@ -30,7 +29,7 @@ namespace mamba std::string build_string = "" ) -> specs::PackageInfo; - std::vector dist_packages(const Context& context); + std::vector dist_packages(const std::string& platform); } } diff --git a/libmamba/src/api/info.cpp b/libmamba/src/api/info.cpp index 3a321b8824..b663c7e632 100644 --- a/libmamba/src/api/info.cpp +++ b/libmamba/src/api/info.cpp @@ -156,7 +156,7 @@ namespace mamba items.push_back({ "populated config files", sources }); std::vector virtual_pkgs; - for (auto pkg : get_virtual_packages(ctx)) + for (auto pkg : get_virtual_packages(ctx.platform)) { virtual_pkgs.push_back(util::concat(pkg.name, "=", pkg.version, "=", pkg.build_string) ); diff --git a/libmamba/src/core/package_database_loader.cpp b/libmamba/src/core/package_database_loader.cpp index 4cdce150c3..221c81f39b 100644 --- a/libmamba/src/core/package_database_loader.cpp +++ b/libmamba/src/core/package_database_loader.cpp @@ -139,7 +139,7 @@ namespace mamba // TODO(C++20): We could do a PrefixData range that returns packages without storing thems. auto pkgs = prefix.sorted_records(); // TODO(C++20): We only need a range that concatenate both - for (auto&& pkg : get_virtual_packages(ctx)) + for (auto&& pkg : get_virtual_packages(ctx.platform)) { pkgs.push_back(std::move(pkg)); } diff --git a/libmamba/src/core/virtual_packages.cpp b/libmamba/src/core/virtual_packages.cpp index fde31ad41e..4b94201441 100644 --- a/libmamba/src/core/virtual_packages.cpp +++ b/libmamba/src/core/virtual_packages.cpp @@ -243,12 +243,11 @@ namespace mamba return util::windows_version(); } - std::vector dist_packages(const Context& context) + std::vector dist_packages(const std::string& platform) { LOG_DEBUG << "Loading distribution virtual packages"; std::vector res; - const auto platform = context.platform; const auto split_platform = util::split(platform, "-", 1); if (split_platform.size() != 2) @@ -342,15 +341,15 @@ namespace mamba } } - std::vector get_virtual_packages(const Context& context) + std::vector get_virtual_packages(const std::string& platform) { LOG_DEBUG << "Loading virtual packages"; - auto res = detail::dist_packages(context); + auto res = detail::dist_packages(platform); auto cuda_ver = detail::cuda_version(); if (!cuda_ver.empty()) { - res.push_back(detail::make_virtual_package("__cuda", context.platform, cuda_ver)); + res.push_back(detail::make_virtual_package("__cuda", platform, cuda_ver)); } return res; diff --git a/libmamba/tests/src/core/test_virtual_packages.cpp b/libmamba/tests/src/core/test_virtual_packages.cpp index c93bc2e6ae..a71108801d 100644 --- a/libmamba/tests/src/core/test_virtual_packages.cpp +++ b/libmamba/tests/src/core/test_virtual_packages.cpp @@ -52,7 +52,7 @@ namespace mamba using Version = specs::Version; auto& ctx = mambatests::context(); - auto pkgs = detail::dist_packages(ctx); + auto pkgs = detail::dist_packages(ctx.platform); if (util::on_win) { @@ -86,9 +86,8 @@ namespace mamba auto restore_ctx = [&ctx, old_plat = ctx.platform]() { ctx.platform = old_plat; }; auto finally = Finally{ restore_ctx }; - ctx.platform = "osx-arm"; util::set_env("CONDA_OVERRIDE_OSX", "12.1"); - pkgs = detail::dist_packages(ctx); + pkgs = detail::dist_packages("osx-arm"); REQUIRE_EQ(pkgs.size(), 3); CHECK_EQ(pkgs[0].name, "__unix"); CHECK_EQ(pkgs[1].name, "__osx"); @@ -97,10 +96,9 @@ namespace mamba CHECK_EQ(pkgs[2].build_string, "arm"); util::unset_env("CONDA_OVERRIDE_OSX"); - ctx.platform = "linux-32"; util::set_env("CONDA_OVERRIDE_LINUX", "5.7"); util::set_env("CONDA_OVERRIDE_GLIBC", "2.15"); - pkgs = detail::dist_packages(ctx); + pkgs = detail::dist_packages("linux-32"); REQUIRE_EQ(pkgs.size(), 4); CHECK_EQ(pkgs[0].name, "__unix"); CHECK_EQ(pkgs[1].name, "__linux"); @@ -112,15 +110,13 @@ namespace mamba util::unset_env("CONDA_OVERRIDE_GLIBC"); util::unset_env("CONDA_OVERRIDE_LINUX"); - ctx.platform = "lin-850"; - pkgs = detail::dist_packages(ctx); + pkgs = detail::dist_packages("lin-850"); REQUIRE_EQ(pkgs.size(), 1); CHECK_EQ(pkgs[0].name, "__archspec"); CHECK_EQ(pkgs[0].build_string, "850"); util::unset_env("CONDA_SUBDIR"); - ctx.platform = "linux"; - pkgs = detail::dist_packages(ctx); + pkgs = detail::dist_packages("linux"); REQUIRE_EQ(pkgs.size(), 0); ctx.platform = ctx.host_platform; @@ -130,7 +126,7 @@ namespace mamba { util::set_env("CONDA_OVERRIDE_CUDA", "9.0"); const auto& context = mambatests::context(); - auto pkgs = get_virtual_packages(context); + auto pkgs = get_virtual_packages(context.platform); int pkgs_count; if (util::on_win) @@ -152,7 +148,7 @@ namespace mamba CHECK_EQ(pkgs.back().version, "9.0"); util::unset_env("CONDA_OVERRIDE_CUDA"); - pkgs = get_virtual_packages(context); + pkgs = get_virtual_packages(context.platform); if (!detail::cuda_version().empty()) { diff --git a/libmambapy/src/libmambapy/bindings/legacy.cpp b/libmambapy/src/libmambapy/bindings/legacy.cpp index 82acce79b3..861de46ec0 100644 --- a/libmambapy/src/libmambapy/bindings/legacy.cpp +++ b/libmambapy/src/libmambapy/bindings/legacy.cpp @@ -1208,7 +1208,10 @@ bind_submodule_impl(pybind11::module_ m) // py::arg("out_package"), py::arg("compression_level"), py::arg("compression_threads") = 1); - m.def("get_virtual_packages", [](Context& context) { return get_virtual_packages(context); }); + m.def( + "get_virtual_packages", + [](Context& context) { return get_virtual_packages(context.platform); } + ); m.def("cancel_json_output", [](Context&) { mambapy::singletons().console().cancel_json_print(); });