No ugly kenum (#2831)

This commit is contained in:
Antoine Prouvost 2023-09-14 10:56:29 +02:00 committed by GitHub
parent 8cb0985cd1
commit 9b757c24a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 89 additions and 95 deletions

View File

@ -200,15 +200,15 @@ namespace YAML
{
static Node encode(const mamba::VerificationLevel& rhs)
{
if (rhs == mamba::VerificationLevel::kDisabled)
if (rhs == mamba::VerificationLevel::Disabled)
{
return Node("disabled");
}
else if (rhs == mamba::VerificationLevel::kWarn)
else if (rhs == mamba::VerificationLevel::Warn)
{
return Node("warn");
}
else if (rhs == mamba::VerificationLevel::kEnabled)
else if (rhs == mamba::VerificationLevel::Enabled)
{
return Node("enabled");
}
@ -229,15 +229,15 @@ namespace YAML
if (str == "enabled")
{
rhs = mamba::VerificationLevel::kEnabled;
rhs = mamba::VerificationLevel::Enabled;
}
else if (str == "warn")
{
rhs = mamba::VerificationLevel::kWarn;
rhs = mamba::VerificationLevel::Warn;
}
else if (str == "disabled")
{
rhs = mamba::VerificationLevel::kDisabled;
rhs = mamba::VerificationLevel::Disabled;
}
else
{
@ -255,15 +255,15 @@ namespace YAML
{
static Node encode(const mamba::ChannelPriority& rhs)
{
if (rhs == mamba::ChannelPriority::kStrict)
if (rhs == mamba::ChannelPriority::Strict)
{
return Node("strict");
}
else if (rhs == mamba::ChannelPriority::kFlexible)
else if (rhs == mamba::ChannelPriority::Flexible)
{
return Node("flexible");
}
else if (rhs == mamba::ChannelPriority::kDisabled)
else if (rhs == mamba::ChannelPriority::Disabled)
{
return Node("disabled");
}
@ -284,15 +284,15 @@ namespace YAML
if (str == "strict")
{
rhs = mamba::ChannelPriority::kStrict;
rhs = mamba::ChannelPriority::Strict;
}
else if ((str == "flexible") || (str == "true"))
{
rhs = mamba::ChannelPriority::kFlexible;
rhs = mamba::ChannelPriority::Flexible;
}
else if (str == "disabled")
{
rhs = mamba::ChannelPriority::kDisabled;
rhs = mamba::ChannelPriority::Disabled;
}
else
{

View File

@ -25,14 +25,14 @@ namespace mamba
{
enum class VerificationLevel
{
kDisabled,
kWarn,
kEnabled
Disabled,
Warn,
Enabled
};
struct ValidationOptions
{
VerificationLevel safety_checks = VerificationLevel::kWarn;
VerificationLevel safety_checks = VerificationLevel::Warn;
bool extra_safety_checks = false;
bool verify_artifacts = false;
};
@ -40,16 +40,16 @@ namespace mamba
enum class ChannelPriority
{
kDisabled,
kFlexible,
kStrict
Disabled,
Flexible,
Strict
};
enum class AuthenticationType
{
kBasicHTTPAuthentication,
kBearerToken,
kCondaToken
BasicHTTPAuthentication,
BearerToken,
CondaToken
};
struct AuthenticationInfo
@ -153,7 +153,7 @@ namespace mamba
std::size_t local_repodata_ttl = 1; // take from header
bool offline = false;
ChannelPriority channel_priority = ChannelPriority::kFlexible;
ChannelPriority channel_priority = ChannelPriority::Flexible;
bool auto_activate_base = false;
bool extract_sparse = false;

View File

@ -82,7 +82,7 @@ namespace mamba
}
auto sdir = std::move(sdires).value();
subdirs.push_back(std::move(sdir));
if (ctx.channel_priority == ChannelPriority::kDisabled)
if (ctx.channel_priority == ChannelPriority::Disabled)
{
priorities.push_back(std::make_pair(0, 0));
}

View File

@ -511,7 +511,7 @@ namespace mamba
{
{ SOLVER_FLAG_ALLOW_UNINSTALL, ctx.allow_uninstall },
{ SOLVER_FLAG_ALLOW_DOWNGRADE, ctx.allow_downgrade },
{ SOLVER_FLAG_STRICT_REPO_PRIORITY, ctx.channel_priority == ChannelPriority::kStrict },
{ SOLVER_FLAG_STRICT_REPO_PRIORITY, ctx.channel_priority == ChannelPriority::Strict },
}
);

View File

@ -129,7 +129,7 @@ namespace mamba
{ SOLVER_FLAG_ALLOW_DOWNGRADE, 1 },
{ SOLVER_FLAG_ALLOW_UNINSTALL, 1 },
{ SOLVER_FLAG_STRICT_REPO_PRIORITY,
ctx.channel_priority == ChannelPriority::kStrict },
ctx.channel_priority == ChannelPriority::Strict },
}
);

View File

@ -75,7 +75,7 @@ namespace mamba
{
{ SOLVER_FLAG_ALLOW_DOWNGRADE, ctx.allow_downgrade },
{ SOLVER_FLAG_ALLOW_UNINSTALL, ctx.allow_uninstall },
{ SOLVER_FLAG_STRICT_REPO_PRIORITY, ctx.channel_priority == ChannelPriority::kStrict },
{ SOLVER_FLAG_STRICT_REPO_PRIORITY, ctx.channel_priority == ChannelPriority::Strict },
}
);

View File

@ -619,12 +619,12 @@ namespace mamba
const auto& authentication_info = m_context.authentication_info();
auto it = authentication_info.find(auth);
if (it != authentication_info.end()
&& it->second.type == AuthenticationType::kCondaToken)
&& it->second.type == AuthenticationType::CondaToken)
{
chan.m_token = it->second.value;
break;
}
else if (it != authentication_info.end() && it->second.type == AuthenticationType::kBasicHTTPAuthentication)
else if (it != authentication_info.end() && it->second.type == AuthenticationType::BasicHTTPAuthentication)
{
chan.m_auth = it->second.value;
break;

View File

@ -224,7 +224,7 @@ namespace mamba
token_url = token_url.substr(0, token_url.size() - 6);
std::string token_content = read_contents(entry.path());
AuthenticationInfo auth_info{ AuthenticationType::kCondaToken, token_content };
AuthenticationInfo auth_info{ AuthenticationType::CondaToken, token_content };
m_authentication_info[token_url] = auth_info;
LOG_INFO << "Found token for " << token_url << " at " << entry.path();
}
@ -247,14 +247,14 @@ namespace mamba
AuthenticationInfo info;
if (type == "CondaToken")
{
info.type = AuthenticationType::kCondaToken;
info.type = AuthenticationType::CondaToken;
info.value = el["token"].get<std::string>();
LOG_INFO << "Found token for host " << host
<< " in ~/.mamba/auth/authentication.json";
}
else if (type == "BasicHTTPAuthentication")
{
info.type = AuthenticationType::kBasicHTTPAuthentication;
info.type = AuthenticationType::BasicHTTPAuthentication;
const auto& user = el.value("user", "");
auto pass = decode_base64(el["password"].get<std::string>());
if (pass)
@ -273,7 +273,7 @@ namespace mamba
}
else if (type == "BearerToken")
{
info.type = AuthenticationType::kBearerToken;
info.type = AuthenticationType::BearerToken;
info.value = el["token"].get<std::string>();
LOG_INFO << "Found bearer token for host " << host
<< " in ~/.mamba/auth/authentication.json";

View File

@ -223,7 +223,7 @@ namespace mamba
if (context.authentication_info().count(host))
{
const auto& auth = context.authentication_info().at(host);
if (auth.type == AuthenticationType::kBearerToken)
if (auth.type == AuthenticationType::BearerToken)
{
m_handle.add_header(fmt::format("Authorization: Bearer {}", auth.value));
}

View File

@ -260,7 +260,7 @@ namespace mamba
if (m_context.authentication_info().count(host))
{
const auto& auth = m_context.authentication_info().at(host);
if (auth.type == AuthenticationType::kBearerToken)
if (auth.type == AuthenticationType::BearerToken)
{
m_curl_handle->add_header(fmt::format("Authorization: Bearer {}", auth.value));
}

View File

@ -139,13 +139,13 @@ namespace mamba
}
else
{
if (options.safety_checks == VerificationLevel::kWarn)
if (options.safety_checks == VerificationLevel::Warn)
{
LOG_WARNING << "Could not validate package '" + tarball_path.string()
+ "': md5 and sha256 sum unknown.\n"
"Set safety_checks to disabled to override this warning.";
}
else if (options.safety_checks == VerificationLevel::kEnabled)
else if (options.safety_checks == VerificationLevel::Enabled)
{
// we cannot validate this archive, but we could also not validate a downloaded
// archive since we just don't know the sha256 or md5 sum
@ -207,14 +207,14 @@ namespace mamba
|| (!s.sha256.empty() && repodata_record.contains("sha256"));
if (!can_validate)
{
if (options.safety_checks == VerificationLevel::kWarn)
if (options.safety_checks == VerificationLevel::Warn)
{
LOG_WARNING
<< "Could not validate package '" + repodata_record_path.string()
+ "': md5 and sha256 sum unknown.\n"
"Set safety_checks to disabled to override this warning.";
}
else if (options.safety_checks == VerificationLevel::kEnabled)
else if (options.safety_checks == VerificationLevel::Enabled)
{
throw std::runtime_error(
"Could not validate package '" + repodata_record_path.string()

View File

@ -830,13 +830,13 @@ namespace mamba
bool validate(const fs::u8path& pkg_folder, const ValidationOptions& options)
{
auto safety_checks = options.safety_checks;
if (safety_checks == VerificationLevel::kDisabled)
if (safety_checks == VerificationLevel::Disabled)
{
return true;
}
bool is_warn = safety_checks == VerificationLevel::kWarn;
bool is_fail = safety_checks == VerificationLevel::kEnabled;
bool is_warn = safety_checks == VerificationLevel::Warn;
bool is_fail = safety_checks == VerificationLevel::Enabled;
bool full_validation = options.extra_safety_checks;
try

View File

@ -492,7 +492,7 @@ namespace mamba
{
auto& ctx = mambatests::context();
ctx.authentication_info()["conda.anaconda.org"] = AuthenticationInfo{
AuthenticationType::kCondaToken,
AuthenticationType::CondaToken,
"my-12345-token"
};
@ -515,11 +515,11 @@ namespace mamba
{
auto& ctx = mambatests::context();
ctx.authentication_info()["conda.anaconda.org"] = AuthenticationInfo{
AuthenticationType::kCondaToken,
AuthenticationType::CondaToken,
"base-token"
};
ctx.authentication_info()["conda.anaconda.org/conda-forge"] = AuthenticationInfo{
AuthenticationType::kCondaToken,
AuthenticationType::CondaToken,
"channel-token"
};

View File

@ -839,23 +839,20 @@ namespace mamba
load_test_config({ rc1, rc2, rc3 });
CHECK_EQ(
config.at("channel_priority").value<ChannelPriority>(),
ChannelPriority::kFlexible
ChannelPriority::Flexible
);
CHECK(ctx.channel_priority == ChannelPriority::kFlexible);
CHECK(ctx.channel_priority == ChannelPriority::Flexible);
load_test_config({ rc3, rc1, rc2 });
CHECK_EQ(
config.at("channel_priority").value<ChannelPriority>(),
ChannelPriority::kDisabled
ChannelPriority::Disabled
);
CHECK(ctx.channel_priority == ChannelPriority::kDisabled);
CHECK(ctx.channel_priority == ChannelPriority::Disabled);
load_test_config({ rc2, rc1, rc3 });
CHECK_EQ(
config.at("channel_priority").value<ChannelPriority>(),
ChannelPriority::kStrict
);
CHECK(ctx.channel_priority == ChannelPriority::kStrict);
CHECK_EQ(config.at("channel_priority").value<ChannelPriority>(), ChannelPriority::Strict);
CHECK(ctx.channel_priority == ChannelPriority::Strict);
env::set("MAMBA_CHANNEL_PRIORITY", "strict");
load_test_config(rc3);
@ -868,11 +865,8 @@ namespace mamba
config.dump(MAMBA_SHOW_CONFIG_VALUES | MAMBA_SHOW_CONFIG_SRCS),
"channel_priority: strict # 'MAMBA_CHANNEL_PRIORITY' > '" + src + "'"
);
CHECK_EQ(
config.at("channel_priority").value<ChannelPriority>(),
ChannelPriority::kStrict
);
CHECK_EQ(ctx.channel_priority, ChannelPriority::kStrict);
CHECK_EQ(config.at("channel_priority").value<ChannelPriority>(), ChannelPriority::Strict);
CHECK_EQ(ctx.channel_priority, ChannelPriority::Strict);
config.at("channel_priority").set_yaml_value("flexible").compute();
CHECK_EQ(
@ -881,9 +875,9 @@ namespace mamba
);
CHECK_EQ(
config.at("channel_priority").value<ChannelPriority>(),
ChannelPriority::kFlexible
ChannelPriority::Flexible
);
CHECK_EQ(ctx.channel_priority, ChannelPriority::kFlexible);
CHECK_EQ(ctx.channel_priority, ChannelPriority::Flexible);
env::set("MAMBA_CHANNEL_PRIORITY", "stric");
REQUIRE_THROWS_AS(load_test_config(rc3), YAML::Exception);
@ -1012,20 +1006,20 @@ namespace mamba
load_test_config({ rc1, rc2, rc3 });
CHECK_EQ(
config.at("safety_checks").value<VerificationLevel>(),
VerificationLevel::kEnabled
VerificationLevel::Enabled
);
CHECK_EQ(ctx.validation_params.safety_checks, VerificationLevel::kEnabled);
CHECK_EQ(ctx.validation_params.safety_checks, VerificationLevel::Enabled);
load_test_config({ rc2, rc1, rc3 });
CHECK_EQ(config.at("safety_checks").value<VerificationLevel>(), VerificationLevel::kWarn);
CHECK_EQ(ctx.validation_params.safety_checks, VerificationLevel::kWarn);
CHECK_EQ(config.at("safety_checks").value<VerificationLevel>(), VerificationLevel::Warn);
CHECK_EQ(ctx.validation_params.safety_checks, VerificationLevel::Warn);
load_test_config({ rc3, rc1, rc3 });
CHECK_EQ(
config.at("safety_checks").value<VerificationLevel>(),
VerificationLevel::kDisabled
VerificationLevel::Disabled
);
CHECK_EQ(ctx.validation_params.safety_checks, VerificationLevel::kDisabled);
CHECK_EQ(ctx.validation_params.safety_checks, VerificationLevel::Disabled);
env::set("MAMBA_SAFETY_CHECKS", "warn");
load_test_config(rc1);
@ -1038,8 +1032,8 @@ namespace mamba
config.dump(MAMBA_SHOW_CONFIG_VALUES | MAMBA_SHOW_CONFIG_SRCS),
"safety_checks: warn # 'MAMBA_SAFETY_CHECKS' > '" + src + "'"
);
CHECK_EQ(config.at("safety_checks").value<VerificationLevel>(), VerificationLevel::kWarn);
CHECK_EQ(ctx.validation_params.safety_checks, VerificationLevel::kWarn);
CHECK_EQ(config.at("safety_checks").value<VerificationLevel>(), VerificationLevel::Warn);
CHECK_EQ(ctx.validation_params.safety_checks, VerificationLevel::Warn);
config.at("safety_checks").set_yaml_value("disabled").compute();
CHECK_EQ(
@ -1048,9 +1042,9 @@ namespace mamba
);
CHECK_EQ(
config.at("safety_checks").value<VerificationLevel>(),
VerificationLevel::kDisabled
VerificationLevel::Disabled
);
CHECK_EQ(ctx.validation_params.safety_checks, VerificationLevel::kDisabled);
CHECK_EQ(ctx.validation_params.safety_checks, VerificationLevel::Disabled);
env::set("MAMBA_SAFETY_CHECKS", "yeap");
REQUIRE_THROWS_AS(load_test_config(rc2), std::runtime_error);

View File

@ -182,11 +182,11 @@ class ChannelPriority:
"""
Members:
kFlexible
Flexible
kStrict
Strict
kDisabled
Disabled
"""
def __eq__(self, other: object) -> bool: ...
@ -208,10 +208,10 @@ class ChannelPriority:
"""
:type: int
"""
__members__: dict # value = {'kFlexible': <ChannelPriority.kFlexible: 1>, 'kStrict': <ChannelPriority.kStrict: 2>, 'kDisabled': <ChannelPriority.kDisabled: 0>}
kDisabled: libmambapy.bindings.ChannelPriority # value = <ChannelPriority.kDisabled: 0>
kFlexible: libmambapy.bindings.ChannelPriority # value = <ChannelPriority.kFlexible: 1>
kStrict: libmambapy.bindings.ChannelPriority # value = <ChannelPriority.kStrict: 2>
Disabled: libmambapy.bindings.ChannelPriority # value = <ChannelPriority.Disabled: 0>
Flexible: libmambapy.bindings.ChannelPriority # value = <ChannelPriority.Flexible: 1>
Strict: libmambapy.bindings.ChannelPriority # value = <ChannelPriority.Strict: 2>
__members__: dict # value = {'Flexible': <ChannelPriority.Flexible: 1>, 'Strict': <ChannelPriority.Strict: 2>, 'Disabled': <ChannelPriority.Disabled: 0>}
pass
class CompressedProblemsGraph:

View File

@ -573,9 +573,9 @@ PYBIND11_MODULE(bindings, m)
.def("download", &MultiDownloadTarget::download);
py::enum_<ChannelPriority>(m, "ChannelPriority")
.value("kFlexible", ChannelPriority::kFlexible)
.value("kStrict", ChannelPriority::kStrict)
.value("kDisabled", ChannelPriority::kDisabled);
.value("Flexible", ChannelPriority::Flexible)
.value("Strict", ChannelPriority::Strict)
.value("Disabled", ChannelPriority::Disabled);
py::enum_<mamba::log_level>(m, "LogLevel")
.value("TRACE", mamba::log_level::trace)

View File

@ -276,11 +276,11 @@ def init_api_context(use_mamba_experimental=False):
api_ctx.use_only_tar_bz2 = context.use_only_tar_bz2
if context.channel_priority is ChannelPriority.STRICT:
api_ctx.channel_priority = api.ChannelPriority.kStrict
api_ctx.channel_priority = api.ChannelPriority.Strict
elif context.channel_priority is ChannelPriority.FLEXIBLE:
api_ctx.channel_priority = api.ChannelPriority.kFlexible
api_ctx.channel_priority = api.ChannelPriority.Flexible
elif context.channel_priority is ChannelPriority.DISABLED:
api_ctx.channel_priority = api.ChannelPriority.kDisabled
api_ctx.channel_priority = api.ChannelPriority.Disabled
def to_conda_channel(channel, platform):

View File

@ -202,9 +202,9 @@ init_channel_parser(CLI::App* subcom, Configuration& config)
override_channels.description()
);
std::map<std::string, ChannelPriority> cp_map = { { "disabled", ChannelPriority::kDisabled },
{ "flexible", ChannelPriority::kFlexible },
{ "strict", ChannelPriority::kStrict } };
std::map<std::string, ChannelPriority> cp_map = { { "disabled", ChannelPriority::Disabled },
{ "flexible", ChannelPriority::Flexible },
{ "strict", ChannelPriority::Strict } };
auto& channel_priority = config.at("channel_priority");
subcom
->add_option(
@ -288,7 +288,7 @@ strict_channel_priority_hook(Configuration& config, bool&)
if (strict_channel_priority.configured())
{
if ((channel_priority.cli_configured() || channel_priority.env_var_configured())
&& (channel_priority.cli_value<ChannelPriority>() != ChannelPriority::kStrict))
&& (channel_priority.cli_value<ChannelPriority>() != ChannelPriority::Strict))
{
throw std::runtime_error("Cannot set both 'strict_channel_priority' and 'channel_priority'."
);
@ -302,7 +302,7 @@ strict_channel_priority_hook(Configuration& config, bool&)
);
}
// Override 'channel_priority' CLI value
channel_priority.set_cli_value(ChannelPriority::kStrict);
channel_priority.set_cli_value(ChannelPriority::Strict);
}
}
}
@ -317,7 +317,7 @@ no_channel_priority_hook(Configuration& config, bool&)
if (no_channel_priority.configured())
{
if ((channel_priority.cli_configured() || channel_priority.env_var_configured())
&& (channel_priority.cli_value<ChannelPriority>() != ChannelPriority::kDisabled))
&& (channel_priority.cli_value<ChannelPriority>() != ChannelPriority::Disabled))
{
throw std::runtime_error("Cannot set both 'no_channel_priority' and 'channel_priority'.");
}
@ -330,7 +330,7 @@ no_channel_priority_hook(Configuration& config, bool&)
);
}
// Override 'channel_priority' CLI value
channel_priority.set_cli_value(ChannelPriority::kDisabled);
channel_priority.set_cli_value(ChannelPriority::Disabled);
}
}
}
@ -422,9 +422,9 @@ init_install_options(CLI::App* subcom, Configuration& config)
shortcuts.description()
);
std::map<std::string, VerificationLevel> vl_map = { { "enabled", VerificationLevel::kEnabled },
{ "warn", VerificationLevel::kWarn },
{ "disabled", VerificationLevel::kDisabled } };
std::map<std::string, VerificationLevel> vl_map = { { "enabled", VerificationLevel::Enabled },
{ "warn", VerificationLevel::Warn },
{ "disabled", VerificationLevel::Disabled } };
auto& safety_checks = config.at("safety_checks");
subcom
->add_option(

View File

@ -138,7 +138,7 @@ handle_solve_request(
*cache_entry.pool,
{ { SOLVER_FLAG_ALLOW_UNINSTALL, ctx.allow_uninstall },
{ SOLVER_FLAG_ALLOW_DOWNGRADE, ctx.allow_downgrade },
{ SOLVER_FLAG_STRICT_REPO_PRIORITY, ctx.channel_priority == ChannelPriority::kStrict } }
{ SOLVER_FLAG_STRICT_REPO_PRIORITY, ctx.channel_priority == ChannelPriority::Strict } }
);
solver.add_jobs(specs, SOLVER_INSTALL);