Skip to content

Commit

Permalink
Add ConfigSrcInfo and move other log vars to corresponding struct
Browse files Browse the repository at this point in the history
  • Loading branch information
Hind-M committed Apr 4, 2023
1 parent 0be67e7 commit 960df8e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 27 deletions.
2 changes: 1 addition & 1 deletion libmamba/include/mamba/api/configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ namespace mamba
}
}

if (rc_configured() && !ctx.no_rc && (level >= ConfigurationLevel::kFile))
if (rc_configured() && !ctx.config_src_info.no_rc && (level >= ConfigurationLevel::kFile))
{
m_sources.insert(m_sources.end(), m_rc_sources.begin(), m_rc_sources.end());
m_values.insert(m_rc_values.begin(), m_rc_values.end());
Expand Down
26 changes: 17 additions & 9 deletions libmamba/include/mamba/core/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ namespace mamba
{
public:

// TODO separate later between configurables and internal variables
struct RemoteFetchInfo
{
// ssl_verify can be either an empty string (regular SSL verification),
Expand All @@ -142,14 +143,23 @@ namespace mamba

bool json{ false };
bool quiet{ false };

std::string log_pattern{ "%^%-9!l%-8n%$ %v" };
std::size_t log_backtrace{ 0 };
};

struct InternalDesignInfo
struct InternalDesignInfo // Non configurable
{
bool no_progress_bars{ false };
Palette palette;
};

struct ConfigSrcInfo // Configurable
{
bool no_rc{ false };
bool no_env{ false };
};

std::string caller_version = "";
std::string conda_version = "3.8.0";
std::string current_command = "mamba";
Expand Down Expand Up @@ -178,11 +188,8 @@ namespace mamba
int extract_threads = 0;
bool extract_sparse = false;

std::string log_pattern = "%^%-9!l%-8n%$ %v";
std::size_t log_backtrace = 0;

bool dev = false;
bool on_ci = false;
bool dev = false; // TODO this is always used as default=false and isn't set anywhere => to
// be removed if this is the case...
bool dry_run = false;
bool download_only = false;
bool always_yes = false;
Expand Down Expand Up @@ -215,12 +222,10 @@ namespace mamba
RemoteFetchInfo remote_fetch_info;
OutputInfo output_info;
InternalDesignInfo internal_design_info;
ConfigSrcInfo config_src_info;

std::map<std::string, std::string> proxy_servers;

bool no_rc = false;
bool no_env = false;

std::size_t lock_timeout = 0;
bool use_lockfiles = true;

Expand Down Expand Up @@ -289,6 +294,9 @@ namespace mamba

private:

// Used internally
bool on_ci = false;

void load_authentication_info();
std::map<std::string, AuthenticationInfo> m_authentication_info;
bool m_authentication_infos_loaded = false;
Expand Down
24 changes: 12 additions & 12 deletions libmamba/src/api/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace mamba
{
bool ConfigurableImplBase::env_var_configured() const
{
if (Context::instance().no_env)
if (Context::instance().config_src_info.no_env)
{
return false;
}
Expand All @@ -50,12 +50,12 @@ namespace mamba

bool ConfigurableImplBase::env_var_active() const
{
return !Context::instance().no_env || (m_name == "no_env");
return !Context::instance().config_src_info.no_env || (m_name == "no_env");
}

bool ConfigurableImplBase::rc_configured() const
{
return m_rc_configured && !Context::instance().no_rc;
return m_rc_configured && !Context::instance().config_src_info.no_rc;
}
}

Expand Down Expand Up @@ -609,7 +609,7 @@ namespace mamba
void post_root_prefix_rc_loading()
{
auto& config = Configuration::instance();
if (!Context::instance().no_rc)
if (!Context::instance().config_src_info.no_rc)
{
rc_loading_hook(RCConfigLevel::kHomeDir);
config.at("no_env").compute(MAMBA_CONF_FORCE_COMPUTE);
Expand All @@ -619,7 +619,7 @@ namespace mamba
void post_target_prefix_rc_loading()
{
auto& config = Configuration::instance();
if (!Context::instance().no_rc)
if (!Context::instance().config_src_info.no_rc)
{
rc_loading_hook(RCConfigLevel::kTargetPrefix);
config.at("no_env").compute(MAMBA_CONF_FORCE_COMPUTE);
Expand Down Expand Up @@ -717,7 +717,7 @@ namespace mamba

if (!files.empty())
{
if (ctx.no_rc)
if (ctx.config_src_info.no_rc)
{
LOG_ERROR << "Configuration files disabled by 'no_rc'";
throw std::runtime_error("Incompatible configuration. Aborting.");
Expand Down Expand Up @@ -1512,7 +1512,7 @@ namespace mamba
be one of {'off', 'fatal', 'error', 'warning', 'info',
'debug', 'trace'}.)")));

insert(Configurable("log_backtrace", &ctx.log_backtrace)
insert(Configurable("log_backtrace", &ctx.output_info.log_backtrace)
.group("Output, Prompt and Flow Control")
.set_rc_configurable()
.set_env_var_names()
Expand All @@ -1521,7 +1521,7 @@ namespace mamba
Set the log backtrace size. It will replay the n last
logs if an error is thrown during the execution.)")));

insert(Configurable("log_pattern", &ctx.log_pattern)
insert(Configurable("log_pattern", &ctx.output_info.log_pattern)
.group("Output, Prompt and Flow Control")
.set_rc_configurable()
.set_env_var_names()
Expand Down Expand Up @@ -1643,12 +1643,12 @@ namespace mamba
.set_env_var_names()
.description("Whether to override rc files by highest precedence"));

insert(Configurable("no_rc", &ctx.no_rc)
insert(Configurable("no_rc", &ctx.config_src_info.no_rc)
.group("Config sources")
.set_env_var_names()
.description("Disable the use of configuration files"));

insert(Configurable("no_env", &ctx.no_env)
insert(Configurable("no_env", &ctx.config_src_info.no_env)
.group("Config sources")
.set_env_var_names()
.description("Disable the use of environment variables"));
Expand Down Expand Up @@ -1789,9 +1789,9 @@ namespace mamba
spdlog::flush_on(spdlog::level::off);

Context::instance().dump_backtrace_no_guards();
if (ctx.log_backtrace > 0)
if (ctx.output_info.log_backtrace > 0)
{
spdlog::enable_backtrace(ctx.log_backtrace);
spdlog::enable_backtrace(ctx.output_info.log_backtrace);
}
else
{
Expand Down
14 changes: 9 additions & 5 deletions libmamba/src/core/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,19 @@ namespace mamba

set_default_signal_handler();

std::shared_ptr<spdlog::logger> l = std::make_shared<Logger>("libmamba", log_pattern, "\n");
std::shared_ptr<spdlog::logger> l = std::make_shared<Logger>(
"libmamba",
output_info.log_pattern,
"\n"
);
std::shared_ptr<spdlog::logger> libcurl_logger = std::make_shared<Logger>(
"libcurl",
log_pattern,
output_info.log_pattern,
""
);
std::shared_ptr<spdlog::logger> libsolv_logger = std::make_shared<Logger>(
"libsolv",
log_pattern,
output_info.log_pattern,
""
);
spdlog::register_logger(libcurl_logger);
Expand Down Expand Up @@ -329,8 +333,8 @@ namespace mamba
PRINT_CTX(out, allow_softlinks);
PRINT_CTX(out, offline);
PRINT_CTX(out, output_info.quiet);
PRINT_CTX(out, no_rc);
PRINT_CTX(out, no_env);
PRINT_CTX(out, config_src_info.no_rc);
PRINT_CTX(out, config_src_info.no_env);
PRINT_CTX(out, remote_fetch_info.ssl_no_revoke);
PRINT_CTX(out, remote_fetch_info.ssl_verify);
PRINT_CTX(out, remote_fetch_info.retry_timeout);
Expand Down

0 comments on commit 960df8e

Please sign in to comment.