mirror of https://github.com/mamba-org/mamba.git
Replace `Context` with `Context::platform` where possible (#3364)
Signed-off-by: Julien Jerphanion <git@jjerphan.xyz>
This commit is contained in:
parent
bdae0a1405
commit
154012f256
|
@ -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,
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
);
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
@ -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;
|
||||
|
|
|
@ -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<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");
|
||||
|
@ -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())
|
||||
{
|
||||
|
|
|
@ -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(); });
|
||||
|
||||
|
|
Loading…
Reference in New Issue