Skip to content

Commit

Permalink
Change PackageInfo types (#3113)
Browse files Browse the repository at this point in the history
Use NoArchType in PackageInfo
  • Loading branch information
AntoinePrv authored Jan 8, 2024
1 parent b849683 commit 6bf43a6
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 19 deletions.
10 changes: 6 additions & 4 deletions libmamba/include/mamba/specs/package_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#include <nlohmann/json_fwd.hpp>

#include "mamba/specs/platform.hpp"

namespace mamba::specs
{
class PackageInfo
Expand All @@ -21,7 +23,6 @@ namespace mamba::specs
std::string name = {};
std::string version = {};
std::string build_string = {};
std::string noarch = {};
std::size_t build_number = 0;
/**
* Could contain "conda-forge", "conda-forge/linux-64", or a url.
Expand All @@ -33,15 +34,16 @@ namespace mamba::specs
std::string subdir = {};
std::string filename = {};
std::string license = {};
std::size_t size = 0;
std::size_t timestamp = 0;
std::string md5 = {};
std::string sha256 = {};
std::string signatures = {};
std::vector<std::string> track_features = {};
std::vector<std::string> depends = {};
std::vector<std::string> constrains = {};
std::string signatures = {};
std::vector<std::string> defaulted_keys = {};
NoArchType noarch = NoArchType::No;
std::size_t size = 0;
std::size_t timestamp = 0;

PackageInfo() = default;
explicit PackageInfo(std::string name);
Expand Down
2 changes: 1 addition & 1 deletion libmamba/src/core/pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ namespace mamba
out.name = s.name();
out.version = s.version();
out.build_string = s.build_string();
out.noarch = s.noarch();
out.noarch = specs::noarch_parse(s.noarch()).value_or(specs::NoArchType::No);
out.build_number = s.build_number();
out.channel = s.channel();
out.package_url = s.url();
Expand Down
6 changes: 5 additions & 1 deletion libmamba/src/core/repo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ namespace mamba
solv.set_name(pkg.name);
solv.set_version(pkg.version);
solv.set_build_string(pkg.build_string);
solv.set_noarch(pkg.noarch);
if (pkg.noarch != specs::NoArchType::No)
{
auto noarch = std::string(specs::noarch_name(pkg.noarch)); // SSO
solv.set_noarch(noarch);
}
solv.set_build_number(pkg.build_number);
solv.set_channel(pkg.channel);
solv.set_url(pkg.package_url);
Expand Down
15 changes: 4 additions & 11 deletions libmamba/src/specs/package_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace mamba::specs
j["timestamp"] = timestamp;
j["build"] = build_string;
j["build_number"] = build_number;
if (!noarch.empty())
if (noarch != NoArchType::No)
{
j["noarch"] = noarch;
}
Expand Down Expand Up @@ -240,7 +240,7 @@ namespace mamba::specs
j["build"] = pkg.build_string;
j["build_string"] = pkg.build_string;
j["build_number"] = pkg.build_number;
if (!pkg.noarch.empty())
if (pkg.noarch != NoArchType::No)
{
j["noarch"] = pkg.noarch;
}
Expand Down Expand Up @@ -302,16 +302,9 @@ namespace mamba::specs
}

// add the noarch type if we know it (only known for installed packages)
if (j.contains("noarch"))
if (auto it = j.find("noarch"); it != j.end())
{
if (j["noarch"].type() == nlohmann::json::value_t::boolean)
{
pkg.noarch = "generic_v1";
}
else
{
pkg.noarch = j.value("noarch", "");
}
pkg.noarch = *it;
}

pkg.depends = j.value("depends", std::vector<std::string>());
Expand Down
9 changes: 9 additions & 0 deletions libmamba/src/specs/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,20 @@ namespace mamba::specs
{
j = noarch_name(noarch);
}
else
{
j = nullptr;
}
}

void from_json(const nlohmann::json& j, NoArchType& noarch)
{
// Legacy deserilization
if (j.is_null())
{
noarch = NoArchType::No;
return;
}
if (j.is_boolean())
{
noarch = j.get<bool>() ? NoArchType::Generic : NoArchType::No;
Expand Down
5 changes: 3 additions & 2 deletions libmambapy/tests/test_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,7 @@ def test_VersionSpec():

def test_PackageInfo():
PackageInfo = libmambapy.specs.PackageInfo
NoArchType = libmambapy.specs.NoArchType

pkg = PackageInfo(name="pkg", version="1.0", build_string="bld", build_number=2)

Expand All @@ -707,8 +708,8 @@ def test_PackageInfo():
assert pkg.build_string == "mybld"
pkg.build_number = 5
assert pkg.build_number == 5
pkg.noarch = "generic"
assert pkg.noarch == "generic"
pkg.noarch = "Generic"
assert pkg.noarch == NoArchType.Generic
pkg.channel = "conda-forge"
assert pkg.channel == "conda-forge"
pkg.package_url = "https://repo.mamba.pm/conda-forge/linux-64/foo-4.0-mybld.conda"
Expand Down

0 comments on commit 6bf43a6

Please sign in to comment.