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

No ugly kenum #2831

Merged
merged 1 commit into from
Sep 14, 2023
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
24 changes: 12 additions & 12 deletions libmamba/include/mamba/api/configuration_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand All @@ -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
{
Expand All @@ -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");
}
Expand All @@ -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
{
Expand Down
22 changes: 11 additions & 11 deletions libmamba/include/mamba/core/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,31 @@ 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;
};


enum class ChannelPriority
{
kDisabled,
kFlexible,
kStrict
Disabled,
Flexible,
Strict
};

enum class AuthenticationType
{
kBasicHTTPAuthentication,
kBearerToken,
kCondaToken
BasicHTTPAuthentication,
BearerToken,
CondaToken
};

struct AuthenticationInfo
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion libmamba/src/api/channel_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
2 changes: 1 addition & 1 deletion libmamba/src/api/install.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
}
);

Expand Down
2 changes: 1 addition & 1 deletion libmamba/src/api/remove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
}
);

Expand Down
2 changes: 1 addition & 1 deletion libmamba/src/api/update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
}
);

Expand Down
4 changes: 2 additions & 2 deletions libmamba/src/core/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions libmamba/src/core/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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)
Expand All @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion libmamba/src/core/download.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
2 changes: 1 addition & 1 deletion libmamba/src/core/fetch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
8 changes: 4 additions & 4 deletions libmamba/src/core/package_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions libmamba/src/core/package_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions libmamba/tests/src/core/test_channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ namespace mamba
{
auto& ctx = mambatests::context();
ctx.authentication_info()["conda.anaconda.org"] = AuthenticationInfo{
AuthenticationType::kCondaToken,
AuthenticationType::CondaToken,
"my-12345-token"
};

Expand All @@ -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"
};

Expand Down
Loading