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

Replace Context with Context::platform where possible #3364

Merged
merged 1 commit into from
Jul 29, 2024
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
5 changes: 2 additions & 3 deletions libmamba/include/mamba/core/virtual_packages.hpp
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this header public?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it yes.

Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ namespace mamba
{
class Context;

std::vector<specs::PackageInfo> get_virtual_packages(const Context& context);
std::vector<specs::PackageInfo> get_virtual_packages(const std::string& platform);

namespace detail
{
std::string cuda_version();
std::string get_arch();

auto make_virtual_package(
std::string name,
Expand All @@ -30,7 +29,7 @@ namespace mamba
std::string build_string = ""
) -> specs::PackageInfo;

std::vector<specs::PackageInfo> dist_packages(const Context& context);
std::vector<specs::PackageInfo> dist_packages(const std::string& platform);
}
}

Expand Down
2 changes: 1 addition & 1 deletion libmamba/src/api/info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ namespace mamba
items.push_back({ "populated config files", sources });

std::vector<std::string> 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)
);
Expand Down
2 changes: 1 addition & 1 deletion libmamba/src/core/package_database_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
9 changes: 4 additions & 5 deletions libmamba/src/core/virtual_packages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,11 @@ namespace mamba
return util::windows_version();
}

std::vector<specs::PackageInfo> dist_packages(const Context& context)
std::vector<specs::PackageInfo> dist_packages(const std::string& platform)
{
LOG_DEBUG << "Loading distribution virtual packages";

std::vector<specs::PackageInfo> res;
const auto platform = context.platform;
const auto split_platform = util::split(platform, "-", 1);

if (split_platform.size() != 2)
Expand Down Expand Up @@ -342,15 +341,15 @@ namespace mamba
}
}

std::vector<specs::PackageInfo> get_virtual_packages(const Context& context)
std::vector<specs::PackageInfo> 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;
Expand Down
18 changes: 7 additions & 11 deletions libmamba/tests/src/core/test_virtual_packages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -86,9 +86,8 @@ namespace mamba
auto restore_ctx = [&ctx, old_plat = ctx.platform]() { ctx.platform = old_plat; };
auto finally = Finally<decltype(restore_ctx)>{ 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");
Expand All @@ -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");
Expand All @@ -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;
Expand All @@ -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)
Expand All @@ -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())
{
Expand Down
5 changes: 4 additions & 1 deletion libmambapy/src/libmambapy/bindings/legacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(); });

Expand Down
Loading