Change PackageInfo types (#3113)

Use NoArchType in PackageInfo
This commit is contained in:
Antoine Prouvost 2024-01-08 17:52:17 +01:00 committed by GitHub
parent b849683139
commit 6bf43a6d4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 28 additions and 19 deletions

View File

@ -12,6 +12,8 @@
#include <nlohmann/json_fwd.hpp>
#include "mamba/specs/platform.hpp"
namespace mamba::specs
{
class PackageInfo
@ -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.
@ -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);

View File

@ -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();

View File

@ -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);

View File

@ -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;
}
@ -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;
}
@ -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>());

View File

@ -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;

View File

@ -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)
@ -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"