Context structuring (#2432)

Context structuring

Co-authored-by: Johan Mabille <johan.mabille@gmail.com>
This commit is contained in:
Hind-M 2023-04-12 21:08:29 +02:00 committed by GitHub
parent 032e404fc8
commit 40c220c4ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
39 changed files with 382 additions and 289 deletions

View File

@ -708,7 +708,7 @@ namespace mamba
} }
} }
if (rc_configured() && !ctx.no_rc && (level >= ConfigurationLevel::kFile)) if (rc_configured() && !ctx.src_params.no_rc && (level >= ConfigurationLevel::kFile))
{ {
m_sources.insert(m_sources.end(), m_rc_sources.begin(), m_rc_sources.end()); 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()); m_values.insert(m_rc_values.begin(), m_rc_values.end());

View File

@ -118,11 +118,58 @@ namespace mamba
{ {
public: public:
std::string caller_version = ""; struct RemoteFetchParams
std::string conda_version = "3.8.0"; {
std::string current_command = "mamba"; // ssl_verify can be either an empty string (regular SSL verification),
std::string custom_banner = ""; // the string "<false>" to indicate no SSL verification, or a path to
bool is_micromamba = false; // a directory with cert files, or a cert file.
std::string ssl_verify{ "" };
bool ssl_no_revoke{ false };
bool curl_initialized{ false }; // non configurable, used in fetch only
std::string user_agent{ "mamba/" LIBMAMBA_VERSION_STRING };
int connect_timeout_secs{ 10 };
// int read_timeout_secs { 60 };
int retry_timeout{ 2 }; // seconds
int retry_backoff{ 3 }; // retry_timeout * retry_backoff
int max_retries{ 3 }; // max number of retries
};
struct OutputParams
{
int verbosity{ 0 };
log_level logging_level{ log_level::warn };
bool json{ false };
bool quiet{ false };
std::string log_pattern{ "%^%-9!l%-8n%$ %v" };
std::size_t log_backtrace{ 0 };
};
struct GraphicsParams
{
bool no_progress_bars{ false };
Palette palette;
};
struct SrcParams
{
bool no_rc{ false };
bool no_env{ false };
};
struct CommandParams
{
std::string caller_version{ "" };
std::string conda_version{ "3.8.0" };
std::string current_command{ "mamba" };
std::string custom_banner{ "" };
bool is_micromamba{ false };
};
// Configurable
bool experimental = false; bool experimental = false;
bool debug = false; bool debug = false;
@ -139,8 +186,7 @@ namespace mamba
bool use_index_cache = false; bool use_index_cache = false;
std::size_t local_repodata_ttl = 1; // take from header std::size_t local_repodata_ttl = 1; // take from header
bool offline = false; bool offline = false;
bool quiet = false;
bool json = false;
ChannelPriority channel_priority = ChannelPriority::kFlexible; ChannelPriority channel_priority = ChannelPriority::kFlexible;
bool auto_activate_base = false; bool auto_activate_base = false;
@ -148,23 +194,12 @@ namespace mamba
int extract_threads = 0; int extract_threads = 0;
bool extract_sparse = false; bool extract_sparse = false;
int verbosity = 0; bool dev = false; // TODO this is always used as default=false and isn't set anywhere => to
void set_verbosity(int lvl); // be removed if this is the case...
void set_log_level(log_level level);
log_level logging_level = log_level::warn;
std::string log_pattern = "%^%-9!l%-8n%$ %v";
std::size_t log_backtrace = 0;
bool dev = false;
bool on_ci = false;
bool dry_run = false; bool dry_run = false;
bool download_only = false; bool download_only = false;
bool always_yes = false; bool always_yes = false;
bool no_progress_bars = false;
Palette palette;
bool allow_softlinks = false; bool allow_softlinks = false;
bool always_copy = false; bool always_copy = false;
bool always_softlink = false; bool always_softlink = false;
@ -190,23 +225,13 @@ namespace mamba
// micromamba only // micromamba only
bool shell_completion = true; bool shell_completion = true;
std::string user_agent = "mamba/" LIBMAMBA_VERSION_STRING; RemoteFetchParams remote_fetch_params;
bool curl_initialized = false; OutputParams output_params;
int connect_timeout_secs = 10; GraphicsParams graphics_params;
// int read_timeout_secs = 60; SrcParams src_params;
int retry_timeout = 2; // seconds CommandParams command_params;
int retry_backoff = 3; // retry_timeout * retry_backoff
int max_retries = 3; // max number of retries
std::map<std::string, std::string> proxy_servers; std::map<std::string, std::string> proxy_servers;
// ssl verify can be either an empty string (regular SSL verification),
// the string "<false>" to indicate no SSL verification, or a path to
// a directory with cert files, or a cert file.
std::string ssl_verify = "";
bool ssl_no_revoke = false;
bool no_rc = false;
bool no_env = false;
std::size_t lock_timeout = 0; std::size_t lock_timeout = 0;
bool use_lockfiles = true; bool use_lockfiles = true;
@ -265,6 +290,9 @@ namespace mamba
void debug_print() const; void debug_print() const;
void dump_backtrace_no_guards(); void dump_backtrace_no_guards();
void set_verbosity(int lvl);
void set_log_level(log_level level);
protected: protected:
Context(); Context();
@ -273,6 +301,9 @@ namespace mamba
private: private:
// Used internally
bool on_ci = false;
void load_authentication_info(); void load_authentication_info();
std::map<std::string, AuthenticationInfo> m_authentication_info; std::map<std::string, AuthenticationInfo> m_authentication_info;
bool m_authentication_infos_loaded = false; bool m_authentication_infos_loaded = false;

View File

@ -33,7 +33,7 @@ namespace mamba
{ {
bool ConfigurableImplBase::env_var_configured() const bool ConfigurableImplBase::env_var_configured() const
{ {
if (Context::instance().no_env) if (Context::instance().src_params.no_env)
{ {
return false; return false;
} }
@ -50,12 +50,12 @@ namespace mamba
bool ConfigurableImplBase::env_var_active() const bool ConfigurableImplBase::env_var_active() const
{ {
return !Context::instance().no_env || (m_name == "no_env"); return !Context::instance().src_params.no_env || (m_name == "no_env");
} }
bool ConfigurableImplBase::rc_configured() const bool ConfigurableImplBase::rc_configured() const
{ {
return m_rc_configured && !Context::instance().no_rc; return m_rc_configured && !Context::instance().src_params.no_rc;
} }
} }
@ -609,7 +609,7 @@ namespace mamba
void post_root_prefix_rc_loading() void post_root_prefix_rc_loading()
{ {
auto& config = Configuration::instance(); auto& config = Configuration::instance();
if (!Context::instance().no_rc) if (!Context::instance().src_params.no_rc)
{ {
rc_loading_hook(RCConfigLevel::kHomeDir); rc_loading_hook(RCConfigLevel::kHomeDir);
config.at("no_env").compute(MAMBA_CONF_FORCE_COMPUTE); config.at("no_env").compute(MAMBA_CONF_FORCE_COMPUTE);
@ -619,7 +619,7 @@ namespace mamba
void post_target_prefix_rc_loading() void post_target_prefix_rc_loading()
{ {
auto& config = Configuration::instance(); auto& config = Configuration::instance();
if (!Context::instance().no_rc) if (!Context::instance().src_params.no_rc)
{ {
rc_loading_hook(RCConfigLevel::kTargetPrefix); rc_loading_hook(RCConfigLevel::kTargetPrefix);
config.at("no_env").compute(MAMBA_CONF_FORCE_COMPUTE); config.at("no_env").compute(MAMBA_CONF_FORCE_COMPUTE);
@ -630,13 +630,13 @@ namespace mamba
{ {
auto& ctx = Context::instance(); auto& ctx = Context::instance();
if (ctx.json) if (ctx.output_params.json)
{ {
return mamba::log_level::off; return mamba::log_level::off;
} }
else if (Configuration::instance().at("verbose").configured()) else if (Configuration::instance().at("verbose").configured())
{ {
switch (ctx.verbosity) switch (ctx.output_params.verbosity)
{ {
case 0: case 0:
return mamba::log_level::warn; return mamba::log_level::warn;
@ -657,7 +657,7 @@ namespace mamba
void verbose_hook(int& lvl) void verbose_hook(int& lvl)
{ {
auto& ctx = Context::instance(); auto& ctx = Context::instance();
ctx.verbosity = lvl; ctx.output_params.verbosity = lvl;
} }
void target_prefix_checks_hook(int& options) void target_prefix_checks_hook(int& options)
@ -717,7 +717,7 @@ namespace mamba
if (!files.empty()) if (!files.empty())
{ {
if (ctx.no_rc) if (ctx.src_params.no_rc)
{ {
LOG_ERROR << "Configuration files disabled by 'no_rc'"; LOG_ERROR << "Configuration files disabled by 'no_rc'";
throw std::runtime_error("Incompatible configuration. Aborting."); throw std::runtime_error("Incompatible configuration. Aborting.");
@ -1217,7 +1217,7 @@ namespace mamba
.set_env_var_names() .set_env_var_names()
.description("Force use cached repodata")); .description("Force use cached repodata"));
insert(Configurable("ssl_no_revoke", &ctx.ssl_no_revoke) insert(Configurable("ssl_no_revoke", &ctx.remote_fetch_params.ssl_no_revoke)
.group("Network") .group("Network")
.set_rc_configurable() .set_rc_configurable()
.set_env_var_names() .set_env_var_names()
@ -1227,7 +1227,7 @@ namespace mamba
It's only working for Windows back-end. It's only working for Windows back-end.
WARNING: this option loosens the SSL security.)"))); WARNING: this option loosens the SSL security.)")));
insert(Configurable("ssl_verify", &ctx.ssl_verify) insert(Configurable("ssl_verify", &ctx.remote_fetch_params.ssl_verify)
.group("Network") .group("Network")
.set_rc_configurable() .set_rc_configurable()
.set_env_var_names() .set_env_var_names()
@ -1249,7 +1249,7 @@ namespace mamba
the value is the url of the proxy server, optionally with username and password the value is the url of the proxy server, optionally with username and password
in the form of scheme://username:password@hostname.)"))); in the form of scheme://username:password@hostname.)")));
insert(Configurable("remote_connect_timeout_secs", &ctx.connect_timeout_secs) insert(Configurable("remote_connect_timeout_secs", &ctx.remote_fetch_params.connect_timeout_secs)
.group("Network") .group("Network")
.set_rc_configurable() .set_rc_configurable()
.set_env_var_names() .set_env_var_names()
@ -1257,14 +1257,14 @@ namespace mamba
"The number seconds conda will wait for your client to establish a connection to a remote url resource." "The number seconds conda will wait for your client to establish a connection to a remote url resource."
)); ));
insert(Configurable("remote_backoff_factor", &ctx.retry_backoff) insert(Configurable("remote_backoff_factor", &ctx.remote_fetch_params.retry_backoff)
.group("Network") .group("Network")
.set_rc_configurable() .set_rc_configurable()
.set_env_var_names() .set_env_var_names()
.description("The factor determines the time HTTP connection should wait for attempt." .description("The factor determines the time HTTP connection should wait for attempt."
)); ));
insert(Configurable("remote_max_retries", &ctx.max_retries) insert(Configurable("remote_max_retries", &ctx.remote_fetch_params.max_retries)
.group("Network") .group("Network")
.set_rc_configurable() .set_rc_configurable()
.set_env_var_names() .set_env_var_names()
@ -1507,7 +1507,7 @@ namespace mamba
.description("Only download and extract packages, do not link them into environment." .description("Only download and extract packages, do not link them into environment."
)); ));
insert(Configurable("log_level", &ctx.logging_level) insert(Configurable("log_level", &ctx.output_params.logging_level)
.group("Output, Prompt and Flow Control") .group("Output, Prompt and Flow Control")
.set_rc_configurable() .set_rc_configurable()
.set_env_var_names() .set_env_var_names()
@ -1519,7 +1519,7 @@ namespace mamba
be one of {'off', 'fatal', 'error', 'warning', 'info', be one of {'off', 'fatal', 'error', 'warning', 'info',
'debug', 'trace'}.)"))); 'debug', 'trace'}.)")));
insert(Configurable("log_backtrace", &ctx.log_backtrace) insert(Configurable("log_backtrace", &ctx.output_params.log_backtrace)
.group("Output, Prompt and Flow Control") .group("Output, Prompt and Flow Control")
.set_rc_configurable() .set_rc_configurable()
.set_env_var_names() .set_env_var_names()
@ -1528,7 +1528,7 @@ namespace mamba
Set the log backtrace size. It will replay the n last Set the log backtrace size. It will replay the n last
logs if an error is thrown during the execution.)"))); logs if an error is thrown during the execution.)")));
insert(Configurable("log_pattern", &ctx.log_pattern) insert(Configurable("log_pattern", &ctx.output_params.log_pattern)
.group("Output, Prompt and Flow Control") .group("Output, Prompt and Flow Control")
.set_rc_configurable() .set_rc_configurable()
.set_env_var_names() .set_env_var_names()
@ -1536,7 +1536,7 @@ namespace mamba
.long_description(unindent(R"( .long_description(unindent(R"(
Set the log pattern.)"))); Set the log pattern.)")));
insert(Configurable("json", &ctx.json) insert(Configurable("json", &ctx.output_params.json)
.group("Output, Prompt and Flow Control") .group("Output, Prompt and Flow Control")
.set_rc_configurable() .set_rc_configurable()
.needs({ "print_config_only", "print_context_only" }) .needs({ "print_config_only", "print_context_only" })
@ -1619,7 +1619,7 @@ namespace mamba
.group("Output, Prompt and Flow Control") .group("Output, Prompt and Flow Control")
.description("Display configs values")); .description("Display configs values"));
insert(Configurable("quiet", &ctx.quiet) insert(Configurable("quiet", &ctx.output_params.quiet)
.group("Output, Prompt and Flow Control") .group("Output, Prompt and Flow Control")
.set_rc_configurable() .set_rc_configurable()
.set_env_var_names() .set_env_var_names()
@ -1650,12 +1650,12 @@ namespace mamba
.set_env_var_names() .set_env_var_names()
.description("Whether to override rc files by highest precedence")); .description("Whether to override rc files by highest precedence"));
insert(Configurable("no_rc", &ctx.no_rc) insert(Configurable("no_rc", &ctx.src_params.no_rc)
.group("Config sources") .group("Config sources")
.set_env_var_names() .set_env_var_names()
.description("Disable the use of configuration files")); .description("Disable the use of configuration files"));
insert(Configurable("no_env", &ctx.no_env) insert(Configurable("no_env", &ctx.src_params.no_env)
.group("Config sources") .group("Config sources")
.set_env_var_names() .set_env_var_names()
.description("Disable the use of environment variables")); .description("Disable the use of environment variables"));
@ -1790,15 +1790,15 @@ namespace mamba
} }
auto& ctx = Context::instance(); auto& ctx = Context::instance();
ctx.set_log_level(ctx.logging_level); ctx.set_log_level(ctx.output_params.logging_level);
spdlog::apply_all([&](std::shared_ptr<spdlog::logger> l) { l->flush(); }); spdlog::apply_all([&](std::shared_ptr<spdlog::logger> l) { l->flush(); });
spdlog::flush_on(spdlog::level::off); spdlog::flush_on(spdlog::level::off);
Context::instance().dump_backtrace_no_guards(); Context::instance().dump_backtrace_no_guards();
if (ctx.log_backtrace > 0) if (ctx.output_params.log_backtrace > 0)
{ {
spdlog::enable_backtrace(ctx.log_backtrace); spdlog::enable_backtrace(ctx.output_params.log_backtrace);
} }
else else
{ {

View File

@ -40,14 +40,15 @@ namespace mamba
std::string banner() std::string banner()
{ {
auto& ctx = Context::instance(); auto& ctx = Context::instance();
return ctx.custom_banner.empty() ? mamba_banner : ctx.custom_banner; return ctx.command_params.custom_banner.empty() ? mamba_banner
: ctx.command_params.custom_banner;
} }
namespace detail namespace detail
{ {
void info_pretty_print(std::vector<std::tuple<std::string, nlohmann::json>> items) void info_pretty_print(std::vector<std::tuple<std::string, nlohmann::json>> items)
{ {
if (Context::instance().json) if (Context::instance().output_params.json)
{ {
return; return;
} }
@ -142,9 +143,9 @@ namespace mamba
items.push_back({ "libmamba version", version() }); items.push_back({ "libmamba version", version() });
if (ctx.is_micromamba && !ctx.caller_version.empty()) if (ctx.command_params.is_micromamba && !ctx.command_params.caller_version.empty())
{ {
items.push_back({ "micromamba version", ctx.caller_version }); items.push_back({ "micromamba version", ctx.command_params.caller_version });
} }
items.push_back({ "curl version", curl_version() }); items.push_back({ "curl version", curl_version() });

View File

@ -143,7 +143,7 @@ namespace mamba
options.working_directory = cwd.c_str(); options.working_directory = cwd.c_str();
Console::stream() << fmt::format( Console::stream() << fmt::format(
Context::instance().palette.external, Context::instance().graphics_params.palette.external,
"\nInstalling {} packages: {}", "\nInstalling {} packages: {}",
pkg_mgr, pkg_mgr,
fmt::join(deps, ", ") fmt::join(deps, ", ")
@ -553,7 +553,7 @@ namespace mamba
Console::instance().print("Possible hints:\n - 'freeze_installed' is turned on\n"); Console::instance().print("Possible hints:\n - 'freeze_installed' is turned on\n");
} }
if (ctx.json) if (ctx.output_params.json)
{ {
Console::instance().json_write({ { "success", false }, Console::instance().json_write({ { "success", false },
{ "solver_problems", solver.all_problems() } }); { "solver_problems", solver.all_problems() } });
@ -566,7 +566,7 @@ namespace mamba
MTransaction trans(pool, solver, package_caches); MTransaction trans(pool, solver, package_caches);
if (ctx.json) if (ctx.output_params.json)
{ {
trans.log_json(); trans.log_json();
} }
@ -616,7 +616,7 @@ namespace mamba
// so they must have been ready in the pool before this line // so they must have been ready in the pool before this line
auto transaction = create_transaction(pool, pkg_caches, others); auto transaction = create_transaction(pool, pkg_caches, others);
if (ctx.json) if (ctx.output_params.json)
{ {
transaction.log_json(); transaction.log_json();
} }

View File

@ -59,7 +59,7 @@ namespace mamba
std::regex spec_pat(regex); std::regex spec_pat(regex);
if (ctx.json) if (ctx.output_params.json)
{ {
auto jout = nlohmann::json::array(); auto jout = nlohmann::json::array();
std::vector<std::string> keys; std::vector<std::string> keys;
@ -137,7 +137,7 @@ namespace mamba
if (requested_specs.find(p.name) != requested_specs.end()) if (requested_specs.find(p.name) != requested_specs.end())
{ {
formatted_name = printers::FormattedString(p.name); formatted_name = printers::FormattedString(p.name);
formatted_name.style = ctx.palette.user; formatted_name.style = ctx.graphics_params.palette.user;
} }
t.add_row({ formatted_name, p.version, p.build, p.channel }); t.add_row({ formatted_name, p.version, p.build, p.channel });
} }

View File

@ -90,7 +90,7 @@ namespace mamba
auto execute_transaction = [&](MTransaction& transaction) auto execute_transaction = [&](MTransaction& transaction)
{ {
if (ctx.json) if (ctx.output_params.json)
{ {
transaction.log_json(); transaction.log_json();
} }

View File

@ -66,7 +66,7 @@ namespace mamba
Query q(pool); Query q(pool);
if (type == QueryType::kSEARCH) if (type == QueryType::kSEARCH)
{ {
if (ctx.json) if (ctx.output_params.json)
{ {
std::cout << q.find(query).groupby("name").json().dump(4); std::cout << q.find(query).groupby("name").json().dump(4);
} }

View File

@ -126,7 +126,7 @@ namespace mamba
else if (action == "hook") else if (action == "hook")
{ {
// TODO do we need to do something wtih `shell_prefix -> root_prefix?`? // TODO do we need to do something wtih `shell_prefix -> root_prefix?`?
if (ctx.json) if (ctx.output_params.json)
{ {
Console::instance().json_write( Console::instance().json_write(
{ { "success", true }, { { "success", true },

View File

@ -133,7 +133,7 @@ namespace mamba
auto execute_transaction = [&](MTransaction& transaction) auto execute_transaction = [&](MTransaction& transaction)
{ {
if (ctx.json) if (ctx.output_params.json)
{ {
transaction.log_json(); transaction.log_json();
} }

View File

@ -88,8 +88,8 @@ namespace mamba
{ {
const bool cout_is_atty = is_atty(std::cout); const bool cout_is_atty = is_atty(std::cout);
no_progress_bars = (on_ci || !cout_is_atty); graphics_params.no_progress_bars = (on_ci || !cout_is_atty);
palette = cout_is_atty ? Palette::terminal() : Palette::no_color(); graphics_params.palette = cout_is_atty ? Palette::terminal() : Palette::no_color();
} }
#ifdef _WIN32 #ifdef _WIN32
@ -100,15 +100,19 @@ namespace mamba
set_default_signal_handler(); 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_params.log_pattern,
"\n"
);
std::shared_ptr<spdlog::logger> libcurl_logger = std::make_shared<Logger>( std::shared_ptr<spdlog::logger> libcurl_logger = std::make_shared<Logger>(
"libcurl", "libcurl",
log_pattern, output_params.log_pattern,
"" ""
); );
std::shared_ptr<spdlog::logger> libsolv_logger = std::make_shared<Logger>( std::shared_ptr<spdlog::logger> libsolv_logger = std::make_shared<Logger>(
"libsolv", "libsolv",
log_pattern, output_params.log_pattern,
"" ""
); );
spdlog::register_logger(libcurl_logger); spdlog::register_logger(libcurl_logger);
@ -116,48 +120,48 @@ namespace mamba
spdlog::set_default_logger(l); spdlog::set_default_logger(l);
logger = std::dynamic_pointer_cast<Logger>(l); logger = std::dynamic_pointer_cast<Logger>(l);
spdlog::set_level(convert_log_level(logging_level)); spdlog::set_level(convert_log_level(output_params.logging_level));
} }
Context::~Context() = default; Context::~Context() = default;
void Context::set_verbosity(int lvl) void Context::set_verbosity(int lvl)
{ {
this->verbosity = lvl; this->output_params.verbosity = lvl;
switch (lvl) switch (lvl)
{ {
case -3: case -3:
this->logging_level = log_level::off; this->output_params.logging_level = log_level::off;
break; break;
case -2: case -2:
this->logging_level = log_level::critical; this->output_params.logging_level = log_level::critical;
break; break;
case -1: case -1:
this->logging_level = log_level::err; this->output_params.logging_level = log_level::err;
break; break;
case 0: case 0:
this->logging_level = log_level::warn; this->output_params.logging_level = log_level::warn;
break; break;
case 1: case 1:
this->logging_level = log_level::info; this->output_params.logging_level = log_level::info;
break; break;
case 2: case 2:
this->logging_level = log_level::debug; this->output_params.logging_level = log_level::debug;
break; break;
case 3: case 3:
this->logging_level = log_level::trace; this->output_params.logging_level = log_level::trace;
break; break;
default: default:
this->logging_level = log_level::info; this->output_params.logging_level = log_level::info;
break; break;
} }
spdlog::set_level(convert_log_level(logging_level)); spdlog::set_level(convert_log_level(output_params.logging_level));
} }
void Context::set_log_level(log_level level) void Context::set_log_level(log_level level)
{ {
logging_level = level; output_params.logging_level = level;
spdlog::set_level(convert_log_level(level)); spdlog::set_level(convert_log_level(level));
} }
@ -328,22 +332,22 @@ namespace mamba
PRINT_CTX(out, always_yes); PRINT_CTX(out, always_yes);
PRINT_CTX(out, allow_softlinks); PRINT_CTX(out, allow_softlinks);
PRINT_CTX(out, offline); PRINT_CTX(out, offline);
PRINT_CTX(out, quiet); PRINT_CTX(out, output_params.quiet);
PRINT_CTX(out, no_rc); PRINT_CTX(out, src_params.no_rc);
PRINT_CTX(out, no_env); PRINT_CTX(out, src_params.no_env);
PRINT_CTX(out, ssl_no_revoke); PRINT_CTX(out, remote_fetch_params.ssl_no_revoke);
PRINT_CTX(out, ssl_verify); PRINT_CTX(out, remote_fetch_params.ssl_verify);
PRINT_CTX(out, retry_timeout); PRINT_CTX(out, remote_fetch_params.retry_timeout);
PRINT_CTX(out, retry_backoff); PRINT_CTX(out, remote_fetch_params.retry_backoff);
PRINT_CTX(out, max_retries); PRINT_CTX(out, remote_fetch_params.max_retries);
PRINT_CTX(out, connect_timeout_secs); PRINT_CTX(out, remote_fetch_params.connect_timeout_secs);
PRINT_CTX(out, add_pip_as_python_dependency); PRINT_CTX(out, add_pip_as_python_dependency);
PRINT_CTX(out, override_channels_enabled); PRINT_CTX(out, override_channels_enabled);
PRINT_CTX(out, use_only_tar_bz2); PRINT_CTX(out, use_only_tar_bz2);
PRINT_CTX(out, auto_activate_base); PRINT_CTX(out, auto_activate_base);
PRINT_CTX(out, extra_safety_checks); PRINT_CTX(out, extra_safety_checks);
PRINT_CTX(out, download_threads); PRINT_CTX(out, download_threads);
PRINT_CTX(out, verbosity); PRINT_CTX(out, output_params.verbosity);
PRINT_CTX(out, channel_alias); PRINT_CTX(out, channel_alias);
out << "channel_priority: " << static_cast<int>(channel_priority) << '\n'; out << "channel_priority: " << static_cast<int>(channel_priority) << '\n';
PRINT_CTX_VEC(out, default_channels); PRINT_CTX_VEC(out, default_channels);

View File

@ -36,7 +36,7 @@ namespace mamba
// DO NOT SET TIMEOUT as it will also take into account multi-start time and // DO NOT SET TIMEOUT as it will also take into account multi-start time and
// it's just wrong curl_easy_setopt(m_handle, CURLOPT_TIMEOUT, // it's just wrong curl_easy_setopt(m_handle, CURLOPT_TIMEOUT,
// Context::instance().read_timeout_secs); // Context::instance().remote_fetch_params.read_timeout_secs);
// TODO while libcurl in conda now _has_ http2 support we need to fix mamba to // TODO while libcurl in conda now _has_ http2 support we need to fix mamba to
// work properly with it this includes: // work properly with it this includes:

View File

@ -42,7 +42,7 @@ namespace mamba
std::size_t DownloadTarget::get_default_retry_timeout() std::size_t DownloadTarget::get_default_retry_timeout()
{ {
return static_cast<std::size_t>(Context::instance().retry_timeout); return static_cast<std::size_t>(Context::instance().remote_fetch_params.retry_timeout);
} }
void DownloadTarget::init_curl_handle(CURL* handle, const std::string& url) void DownloadTarget::init_curl_handle(CURL* handle, const std::string& url)
@ -55,16 +55,16 @@ namespace mamba
std::string ssl_no_revoke_env = std::getenv("MAMBA_SSL_NO_REVOKE") std::string ssl_no_revoke_env = std::getenv("MAMBA_SSL_NO_REVOKE")
? std::getenv("MAMBA_SSL_NO_REVOKE") ? std::getenv("MAMBA_SSL_NO_REVOKE")
: "0"; : "0";
bool set_ssl_no_revoke = (Context::instance().ssl_no_revoke || ssl_no_revoke_env != "0"); bool set_ssl_no_revoke = (Context::instance().remote_fetch_params.ssl_no_revoke || ssl_no_revoke_env != "0");
curl::configure_curl_handle( curl::configure_curl_handle(
handle, handle,
url, url,
(no_low_speed_limit == "0"), (no_low_speed_limit == "0"),
Context::instance().connect_timeout_secs, Context::instance().remote_fetch_params.connect_timeout_secs,
set_ssl_no_revoke, set_ssl_no_revoke,
proxy_match(url), proxy_match(url),
Context::instance().ssl_verify Context::instance().remote_fetch_params.ssl_verify
); );
} }
@ -94,12 +94,12 @@ namespace mamba
{ {
auto& ctx = Context::instance(); auto& ctx = Context::instance();
if (!ctx.curl_initialized) if (!ctx.remote_fetch_params.curl_initialized)
{ {
if (ctx.ssl_verify == "<false>") if (ctx.remote_fetch_params.ssl_verify == "<false>")
{ {
LOG_DEBUG << "'ssl_verify' not activated, skipping cURL SSL init"; LOG_DEBUG << "'ssl_verify' not activated, skipping cURL SSL init";
ctx.curl_initialized = true; ctx.remote_fetch_params.curl_initialized = true;
return; return;
} }
@ -125,12 +125,13 @@ namespace mamba
} }
#endif #endif
if (!ctx.ssl_verify.size() && std::getenv("REQUESTS_CA_BUNDLE") != nullptr) if (!ctx.remote_fetch_params.ssl_verify.size()
&& std::getenv("REQUESTS_CA_BUNDLE") != nullptr)
{ {
ctx.ssl_verify = std::getenv("REQUESTS_CA_BUNDLE"); ctx.remote_fetch_params.ssl_verify = std::getenv("REQUESTS_CA_BUNDLE");
LOG_INFO << "Using REQUESTS_CA_BUNDLE " << ctx.ssl_verify; LOG_INFO << "Using REQUESTS_CA_BUNDLE " << ctx.remote_fetch_params.ssl_verify;
} }
else if (ctx.ssl_verify == "<system>" && on_linux) else if (ctx.remote_fetch_params.ssl_verify == "<system>" && on_linux)
{ {
std::array<std::string, 6> cert_locations{ std::array<std::string, 6> cert_locations{
"/etc/ssl/certs/ca-certificates.crt", // Debian/Ubuntu/Gentoo etc. "/etc/ssl/certs/ca-certificates.crt", // Debian/Ubuntu/Gentoo etc.
@ -146,7 +147,7 @@ namespace mamba
{ {
if (fs::exists(loc)) if (fs::exists(loc))
{ {
ctx.ssl_verify = loc; ctx.remote_fetch_params.ssl_verify = loc;
found = true; found = true;
} }
} }
@ -158,7 +159,7 @@ namespace mamba
} }
} }
ctx.curl_initialized = true; ctx.remote_fetch_params.curl_initialized = true;
} }
} }
@ -204,13 +205,13 @@ namespace mamba
std::string user_agent = fmt::format( std::string user_agent = fmt::format(
"User-Agent: {} {}", "User-Agent: {} {}",
Context::instance().user_agent, Context::instance().remote_fetch_params.user_agent,
curl_version() curl_version()
); );
m_curl_handle->add_header(user_agent); m_curl_handle->add_header(user_agent);
m_curl_handle->set_opt_header(); m_curl_handle->set_opt_header();
m_curl_handle->set_opt(CURLOPT_VERBOSE, Context::instance().verbosity >= 2); m_curl_handle->set_opt(CURLOPT_VERBOSE, Context::instance().output_params.verbosity >= 2);
auto logger = spdlog::get("libcurl"); auto logger = spdlog::get("libcurl");
m_curl_handle->set_opt(CURLOPT_DEBUGFUNCTION, curl_debug_callback); m_curl_handle->set_opt(CURLOPT_DEBUGFUNCTION, curl_debug_callback);
@ -243,7 +244,7 @@ namespace mamba
break; break;
} }
return m_retries < size_t(Context::instance().max_retries) return m_retries < size_t(Context::instance().remote_fetch_params.max_retries)
&& (http_status == 413 || http_status == 429 || http_status >= 500) && (http_status == 413 || http_status == 429 || http_status >= 500)
&& !starts_with(m_url, "file://"); && !starts_with(m_url, "file://");
} }
@ -268,7 +269,9 @@ namespace mamba
m_curl_handle->set_opt(CURLOPT_XFERINFODATA, this); m_curl_handle->set_opt(CURLOPT_XFERINFODATA, this);
} }
m_retry_wait_seconds = m_retry_wait_seconds m_retry_wait_seconds = m_retry_wait_seconds
* static_cast<std::size_t>(Context::instance().retry_backoff); * static_cast<std::size_t>(
Context::instance().remote_fetch_params.retry_backoff
);
m_next_retry = now + std::chrono::seconds(m_retry_wait_seconds); m_next_retry = now + std::chrono::seconds(m_retry_wait_seconds);
m_retries++; m_retries++;
return m_curl_handle->handle(); return m_curl_handle->handle();
@ -798,7 +801,8 @@ namespace mamba
// be sure the progress bar manager was not already started // be sure the progress bar manager was not already started
// it would mean this code is part of a larger process using progress bars // it would mean this code is part of a larger process using progress bars
bool pbar_manager_started = pbar_manager.started(); bool pbar_manager_started = pbar_manager.started();
if (!(ctx.no_progress_bars || ctx.json || ctx.quiet || pbar_manager_started)) if (!(ctx.graphics_params.no_progress_bars || ctx.output_params.json
|| ctx.output_params.quiet || pbar_manager_started))
{ {
pbar_manager.watch_print(); pbar_manager.watch_print();
} }
@ -878,7 +882,8 @@ namespace mamba
return false; return false;
} }
if (!(ctx.no_progress_bars || ctx.json || ctx.quiet || pbar_manager_started)) if (!(ctx.graphics_params.no_progress_bars || ctx.output_params.json
|| ctx.output_params.quiet || pbar_manager_started))
{ {
pbar_manager.terminate(); pbar_manager.terminate();
if (!no_clear_progress_bars) if (!no_clear_progress_bars)

View File

@ -30,8 +30,8 @@ namespace mamba
{ {
ur.date = mbstr; ur.date = mbstr;
} }
ur.cmd = Context::instance().current_command; ur.cmd = Context::instance().command_params.current_command;
ur.conda_version = Context::instance().conda_version; ur.conda_version = Context::instance().command_params.conda_version;
return ur; return ur;
} }

View File

@ -437,7 +437,7 @@ namespace mamba
auto [status, ec] = reproc::run(command_args, options); auto [status, ec] = reproc::run(command_args, options);
auto msg = get_prefix_messages(envmap["PREFIX"]); auto msg = get_prefix_messages(envmap["PREFIX"]);
if (Context::instance().json) if (Context::instance().output_params.json)
{ {
// TODO implement cerr also on Console? // TODO implement cerr also on Console?
std::cerr << msg; std::cerr << msg;
@ -733,7 +733,7 @@ namespace mamba
#if defined(__APPLE__) #if defined(__APPLE__)
if (binary_changed && m_pkg_info.subdir == "osx-arm64") if (binary_changed && m_pkg_info.subdir == "osx-arm64")
{ {
codesign(dst, Context::instance().verbosity > 1); codesign(dst, Context::instance().output_params.verbosity > 1);
} }
#endif #endif
return std::make_tuple(validation::sha256sum(dst), rel_dst.string()); return std::make_tuple(validation::sha256sum(dst), rel_dst.string());

View File

@ -324,7 +324,8 @@ namespace mamba
void Console::print(std::string_view str, bool force_print) void Console::print(std::string_view str, bool force_print)
{ {
if (force_print || !(Context::instance().quiet || Context::instance().json)) if (force_print
|| !(Context::instance().output_params.quiet || Context::instance().output_params.json))
{ {
const std::lock_guard<std::mutex> lock(p_data->m_mutex); const std::lock_guard<std::mutex> lock(p_data->m_mutex);
@ -406,7 +407,7 @@ namespace mamba
ProgressProxy Console::add_progress_bar(const std::string& name, size_t expected_total) ProgressProxy Console::add_progress_bar(const std::string& name, size_t expected_total)
{ {
if (Context::instance().no_progress_bars) if (Context::instance().graphics_params.no_progress_bars)
{ {
return ProgressProxy(); return ProgressProxy();
} }
@ -465,7 +466,7 @@ namespace mamba
// is then a JSON object // is then a JSON object
void Console::json_write(const nlohmann::json& j) void Console::json_write(const nlohmann::json& j)
{ {
if (Context::instance().json) if (Context::instance().output_params.json)
{ {
nlohmann::json tmp = j.flatten(); nlohmann::json tmp = j.flatten();
for (auto it = tmp.begin(); it != tmp.end(); ++it) for (auto it = tmp.begin(); it != tmp.end(); ++it)
@ -478,7 +479,7 @@ namespace mamba
// append a value to the current entry, which is then a list // append a value to the current entry, which is then a list
void Console::json_append(const std::string& value) void Console::json_append(const std::string& value)
{ {
if (Context::instance().json) if (Context::instance().output_params.json)
{ {
p_data->json_log[p_data->json_hier + '/' + std::to_string(p_data->json_index)] = value; p_data->json_log[p_data->json_hier + '/' + std::to_string(p_data->json_index)] = value;
p_data->json_index += 1; p_data->json_index += 1;
@ -488,7 +489,7 @@ namespace mamba
// append a JSON object to the current entry, which is then a list // append a JSON object to the current entry, which is then a list
void Console::json_append(const nlohmann::json& j) void Console::json_append(const nlohmann::json& j)
{ {
if (Context::instance().json) if (Context::instance().output_params.json)
{ {
nlohmann::json tmp = j.flatten(); nlohmann::json tmp = j.flatten();
for (auto it = tmp.begin(); it != tmp.end(); ++it) for (auto it = tmp.begin(); it != tmp.end(); ++it)
@ -503,7 +504,7 @@ namespace mamba
// go down in the hierarchy in the "key" entry, create it if it doesn't exist // go down in the hierarchy in the "key" entry, create it if it doesn't exist
void Console::json_down(const std::string& key) void Console::json_down(const std::string& key)
{ {
if (Context::instance().json) if (Context::instance().output_params.json)
{ {
p_data->json_hier += '/' + key; p_data->json_hier += '/' + key;
p_data->json_index = 0; p_data->json_index = 0;
@ -513,7 +514,7 @@ namespace mamba
// go up in the hierarchy // go up in the hierarchy
void Console::json_up() void Console::json_up()
{ {
if (Context::instance().json && !p_data->json_hier.empty()) if (Context::instance().output_params.json && !p_data->json_hier.empty())
{ {
p_data->json_hier.erase(p_data->json_hier.rfind('/')); p_data->json_hier.erase(p_data->json_hier.rfind('/'));
} }
@ -558,7 +559,7 @@ namespace mamba
{ {
case log_level::critical: case log_level::critical:
SPDLOG_CRITICAL(prepend(str, "", std::string(4, ' ').c_str())); SPDLOG_CRITICAL(prepend(str, "", std::string(4, ' ').c_str()));
if (Context::instance().logging_level != log_level::off) if (Context::instance().output_params.logging_level != log_level::off)
{ {
spdlog::dump_backtrace(); spdlog::dump_backtrace();
} }

View File

@ -738,7 +738,7 @@ namespace mamba
void extract_subproc(const fs::u8path& file, const fs::u8path& dest) void extract_subproc(const fs::u8path& file, const fs::u8path& dest)
{ {
std::vector<std::string> args; std::vector<std::string> args;
if (Context::instance().is_micromamba) if (Context::instance().command_params.is_micromamba)
{ {
args = { get_self_exe_path().string(), "package", "extract", file.string(), dest.string() }; args = { get_self_exe_path().string(), "package", "extract", file.string(), dest.string() };
} }

View File

@ -49,7 +49,7 @@ namespace mamba
{ {
dbg->first->warn(log); dbg->first->warn(log);
} }
else if (Context::instance().verbosity > 2) else if (Context::instance().output_params.verbosity > 2)
{ {
dbg->first->info(log); dbg->first->info(log);
} }
@ -104,9 +104,9 @@ namespace mamba
{ {
// ensure that debug logging goes to stderr as to not interfere with stdout json output // ensure that debug logging goes to stderr as to not interfere with stdout json output
pool()->debugmask |= SOLV_DEBUG_TO_STDERR; pool()->debugmask |= SOLV_DEBUG_TO_STDERR;
if (Context::instance().verbosity > 2) if (Context::instance().output_params.verbosity > 2)
{ {
pool_setdebuglevel(pool(), Context::instance().verbosity - 1); pool_setdebuglevel(pool(), Context::instance().output_params.verbosity - 1);
auto logger = spdlog::get("libsolv"); auto logger = spdlog::get("libsolv");
m_data->debug_logger.first = logger.get(); m_data->debug_logger.first = logger.get();
pool_setdebugcallback(pool(), &libsolv_debug_callback, &(m_data->debug_logger)); pool_setdebugcallback(pool(), &libsolv_debug_callback, &(m_data->debug_logger));

View File

@ -522,9 +522,9 @@ namespace mamba
*******************/ *******************/
ProgressBarRepr::ProgressBarRepr() ProgressBarRepr::ProgressBarRepr()
: m_style_none(Context::instance().palette.progress_bar_none) : m_style_none(Context::instance().graphics_params.palette.progress_bar_none)
, m_style_downloaded(Context::instance().palette.progress_bar_downloaded) , m_style_downloaded(Context::instance().graphics_params.palette.progress_bar_downloaded)
, m_style_extracted(Context::instance().palette.progress_bar_extracted) , m_style_extracted(Context::instance().graphics_params.palette.progress_bar_extracted)
, m_ascii_only(Context::instance().ascii_only) , m_ascii_only(Context::instance().ascii_only)
{ {
} }

View File

@ -553,7 +553,7 @@ namespace mamba
{ {
print_prefix(to); print_prefix(to);
m_out << g.node(to).name m_out << g.node(to).name
<< fmt::format(Context::instance().palette.shown, " already visited\n"); << fmt::format(Context::instance().graphics_params.palette.shown, " already visited\n");
} }
void finish_edge(node_id /*from*/, node_id to, const graph_type& /*g*/) void finish_edge(node_id /*from*/, node_id to, const graph_type& /*g*/)

View File

@ -363,7 +363,7 @@ namespace mamba
if (detach) if (detach)
{ {
Console::stream() << fmt::format( Console::stream() << fmt::format(
Context::instance().palette.success, Context::instance().graphics_params.palette.success,
"Running wrapped script {} in the background\n", "Running wrapped script {} in the background\n",
fmt::join(command, " ") fmt::join(command, " ")
); );

View File

@ -115,7 +115,7 @@ namespace mamba
fmt::print( fmt::print(
out, out,
"Setting cmd.exe AUTORUN to: {}", "Setting cmd.exe AUTORUN to: {}",
fmt::styled(to_utf8(value), Context::instance().palette.success) fmt::styled(to_utf8(value), Context::instance().graphics_params.palette.success)
); );
winreg::RegKey key{ HKEY_CURRENT_USER, reg_path }; winreg::RegKey key{ HKEY_CURRENT_USER, reg_path };
@ -172,7 +172,10 @@ namespace mamba
fmt::print( fmt::print(
out, out,
"{}", "{}",
fmt::styled("cmd.exe already initialized.", Context::instance().palette.success) fmt::styled(
"cmd.exe already initialized.",
Context::instance().graphics_params.palette.success
)
); );
} }
} }
@ -214,7 +217,10 @@ namespace mamba
fmt::print( fmt::print(
out, out,
"{}", "{}",
fmt::styled("cmd.exe not initialized yet.", Context::instance().palette.success) fmt::styled(
"cmd.exe not initialized yet.",
Context::instance().graphics_params.palette.success
)
); );
} }
} }
@ -450,7 +456,7 @@ namespace mamba
out, out,
"Adding (or replacing) the following in your {} file\n{}", "Adding (or replacing) the following in your {} file\n{}",
fmt::streamed(file_path), fmt::streamed(file_path),
fmt::styled(conda_init_content, Context::instance().palette.success) fmt::styled(conda_init_content, Context::instance().graphics_params.palette.success)
); );
if (Context::instance().dry_run) if (Context::instance().dry_run)
@ -496,7 +502,7 @@ namespace mamba
fmt::streamed(file_path), fmt::streamed(file_path),
fmt::styled( fmt::styled(
"# >>> mamba initialize >>>\n...\n# <<< mamba initialize <<<", "# >>> mamba initialize >>>\n...\n# <<< mamba initialize <<<",
Context::instance().palette.success Context::instance().graphics_params.palette.success
) )
); );
@ -868,7 +874,7 @@ namespace mamba
out, out,
"Adding (or replacing) the following in your {} file\n{}", "Adding (or replacing) the following in your {} file\n{}",
fmt::streamed(profile_path), fmt::streamed(profile_path),
fmt::styled(conda_init_content, Context::instance().palette.success) fmt::styled(conda_init_content, Context::instance().graphics_params.palette.success)
); );
if (found_mamba_initialize) if (found_mamba_initialize)
@ -932,7 +938,7 @@ namespace mamba
fmt::streamed(profile_path), fmt::streamed(profile_path),
fmt::styled( fmt::styled(
"#region mamba initialize\n...\n#endregion\n", "#region mamba initialize\n...\n#endregion\n",
Context::instance().palette.success Context::instance().graphics_params.palette.success
) )
); );
} }

View File

@ -569,7 +569,8 @@ namespace mamba
print_problem_tree_msg( print_problem_tree_msg(
out, out,
cp_pbs, cp_pbs,
{ /* .unavailable= */ ctx.palette.failure, /* .available= */ ctx.palette.success } { /* .unavailable= */ ctx.graphics_params.palette.failure,
/* .available= */ ctx.graphics_params.palette.success }
); );
return out; return out;
} }

View File

@ -614,7 +614,8 @@ namespace mamba
m_check_targets.back()->set_head_only(true); m_check_targets.back()->set_head_only(true);
m_check_targets.back()->set_finalize_callback(&MSubdirData::finalize_check, this); m_check_targets.back()->set_finalize_callback(&MSubdirData::finalize_check, this);
m_check_targets.back()->set_ignore_failure(true); m_check_targets.back()->set_ignore_failure(true);
if (!(ctx.no_progress_bars || ctx.quiet || ctx.json)) if (!(ctx.graphics_params.no_progress_bars || ctx.output_params.quiet
|| ctx.output_params.json))
{ {
m_progress_bar_check = Console::instance().add_progress_bar( m_progress_bar_check = Console::instance().add_progress_bar(
m_name + " (check zst)" m_name + " (check zst)"
@ -913,7 +914,8 @@ namespace mamba
m_repodata_url + (use_zst ? ".zst" : ""), m_repodata_url + (use_zst ? ".zst" : ""),
m_temp_file->path().string() m_temp_file->path().string()
); );
if (!(ctx.no_progress_bars || ctx.quiet || ctx.json)) if (!(ctx.graphics_params.no_progress_bars || ctx.output_params.quiet
|| ctx.output_params.json))
{ {
m_progress_bar = Console::instance().add_progress_bar(m_name); m_progress_bar = Console::instance().add_progress_bar(m_name);
m_target->set_progress_bar(m_progress_bar); m_target->set_progress_bar(m_progress_bar);

View File

@ -79,7 +79,7 @@ namespace mamba
m_filename = pkg_info.fn; m_filename = pkg_info.fn;
// only do this for micromamba for now // only do this for micromamba for now
if (Context::instance().is_micromamba) if (Context::instance().command_params.is_micromamba)
{ {
m_url = make_channel(pkg_info.url).urls(true)[0]; m_url = make_channel(pkg_info.url).urls(true)[0];
} }
@ -95,7 +95,9 @@ namespace mamba
m_md5 = pkg_info.md5; m_md5 = pkg_info.md5;
auto& ctx = Context::instance(); auto& ctx = Context::instance();
m_has_progress_bars = !(ctx.no_progress_bars || ctx.quiet || ctx.json); m_has_progress_bars = !(
ctx.graphics_params.no_progress_bars || ctx.output_params.quiet || ctx.output_params.json
);
} }
void PackageDownloadExtractTarget::write_repodata_record(const fs::u8path& base_path) void PackageDownloadExtractTarget::write_repodata_record(const fs::u8path& base_path)
@ -1226,12 +1228,13 @@ namespace mamba
fmt::print( fmt::print(
out, out,
"Content trust verifications successful, {} ", "Content trust verifications successful, {} ",
fmt::styled("package(s) are trusted", Context::instance().palette.safe) fmt::styled("package(s) are trusted", Context::instance().graphics_params.palette.safe)
); );
LOG_INFO << "All package(s) are trusted"; LOG_INFO << "All package(s) are trusted";
} }
if (!(ctx.no_progress_bars || ctx.json || ctx.quiet)) if (!(ctx.graphics_params.no_progress_bars || ctx.output_params.json
|| ctx.output_params.quiet))
{ {
interruption_guard g([]() { Console::instance().progress_bar_manager().terminate(); }); interruption_guard g([]() { Console::instance().progress_bar_manager().terminate(); });
@ -1354,7 +1357,8 @@ namespace mamba
std::this_thread::sleep_for(std::chrono::milliseconds(100)); std::this_thread::sleep_for(std::chrono::milliseconds(100));
} }
if (!(ctx.no_progress_bars || ctx.json || ctx.quiet)) if (!(ctx.graphics_params.no_progress_bars || ctx.output_params.json
|| ctx.output_params.quiet))
{ {
pbar_manager.terminate(); pbar_manager.terminate();
pbar_manager.clear_progress_bars(); pbar_manager.clear_progress_bars();
@ -1397,7 +1401,7 @@ namespace mamba
{ {
const auto& ctx = Context::instance(); const auto& ctx = Context::instance();
if (ctx.json) if (ctx.output_params.json)
{ {
return; return;
} }
@ -1490,7 +1494,7 @@ namespace mamba
if (!need_pkg_download(mk_pkginfo(m_pool, s), m_multi_cache)) if (!need_pkg_download(mk_pkginfo(m_pool, s), m_multi_cache))
{ {
dlsize_s.s = "Cached"; dlsize_s.s = "Cached";
dlsize_s.style = ctx.palette.addition; dlsize_s.style = ctx.graphics_params.palette.addition;
} }
else else
{ {
@ -1509,15 +1513,15 @@ namespace mamba
name.s = fmt::format("{} {}", diff, pool_id2str(m_pool, s->name)); name.s = fmt::format("{} {}", diff, pool_id2str(m_pool, s->name));
if (status == Status::install) if (status == Status::install)
{ {
name.style = ctx.palette.addition; name.style = ctx.graphics_params.palette.addition;
} }
else if (status == Status::ignore) else if (status == Status::ignore)
{ {
name.style = ctx.palette.ignored; name.style = ctx.graphics_params.palette.ignored;
} }
else if (status == Status::remove) else if (status == Status::remove)
{ {
name.style = ctx.palette.deletion; name.style = ctx.graphics_params.palette.deletion;
} }
const char* build_string = solvable_lookup_str(s, SOLVABLE_BUILDFLAVOR); const char* build_string = solvable_lookup_str(s, SOLVABLE_BUILDFLAVOR);

View File

@ -1286,7 +1286,8 @@ namespace mamba
// TODO // TODO
std::string CONDA_PACKAGE_ROOT = ""; std::string CONDA_PACKAGE_ROOT = "";
std::string bat_name = Context::instance().is_micromamba ? "micromamba.bat" : "conda.bat"; std::string bat_name = Context::instance().command_params.is_micromamba ? "micromamba.bat"
: "conda.bat";
if (dev_mode) if (dev_mode)
{ {
@ -1297,7 +1298,7 @@ namespace mamba
conda_bat = env::get("CONDA_BAT") conda_bat = env::get("CONDA_BAT")
.value_or((fs::absolute(root_prefix) / "condabin" / bat_name).string()); .value_or((fs::absolute(root_prefix) / "condabin" / bat_name).string());
} }
if (!fs::exists(conda_bat) && Context::instance().is_micromamba) if (!fs::exists(conda_bat) && Context::instance().command_params.is_micromamba)
{ {
// this adds in the needed .bat files for activation // this adds in the needed .bat files for activation
init_root_prefix_cmdexe(Context::instance().root_prefix); init_root_prefix_cmdexe(Context::instance().root_prefix);
@ -1353,7 +1354,7 @@ namespace mamba
std::string shebang, dev_arg; std::string shebang, dev_arg;
if (!Context::instance().is_micromamba) if (!Context::instance().command_params.is_micromamba)
{ {
// During tests, we sometimes like to have a temp env with e.g. an old python // During tests, we sometimes like to have a temp env with e.g. an old python
// in it and have it run tests against the very latest development sources. // in it and have it run tests against the very latest development sources.
@ -1400,7 +1401,7 @@ namespace mamba
} }
out << "eval \"$(" << hook_quoted.str() << ")\"\n"; out << "eval \"$(" << hook_quoted.str() << ")\"\n";
if (!Context::instance().is_micromamba) if (!Context::instance().command_params.is_micromamba)
{ {
out << "conda activate " << dev_arg << " " << std::quoted(prefix.string()) << "\n"; out << "conda activate " << dev_arg << " " << std::quoted(prefix.string()) << "\n";
} }

View File

@ -167,7 +167,7 @@ namespace mamba
"{}", "{}",
fmt::styled( fmt::styled(
"Windows long-path support already enabled.", "Windows long-path support already enabled.",
Context::instance().palette.ignored Context::instance().graphics_params.palette.ignored
) )
); );
return true; return true;
@ -207,7 +207,10 @@ namespace mamba
fmt::print( fmt::print(
out, out,
"{}", "{}",
fmt::styled("Windows long-path support enabled.", Context::instance().palette.success) fmt::styled(
"Windows long-path support enabled.",
Context::instance().graphics_params.palette.success
)
); );
return true; return true;
} }

View File

@ -35,7 +35,7 @@ namespace mamba
Configuration() Configuration()
{ {
m_channel_alias_bu = ctx.channel_alias; m_channel_alias_bu = ctx.channel_alias;
m_ssl_verify = ctx.ssl_verify; m_ssl_verify = ctx.remote_fetch_params.ssl_verify;
m_proxy_servers = ctx.proxy_servers; m_proxy_servers = ctx.proxy_servers;
mamba::Configuration::instance().at("show_banner").set_default_value(false); mamba::Configuration::instance().at("show_banner").set_default_value(false);
} }
@ -44,7 +44,7 @@ namespace mamba
{ {
config.reset_configurables(); config.reset_configurables();
ctx.channel_alias = m_channel_alias_bu; ctx.channel_alias = m_channel_alias_bu;
ctx.ssl_verify = m_ssl_verify; ctx.remote_fetch_params.ssl_verify = m_ssl_verify;
ctx.proxy_servers = m_proxy_servers; ctx.proxy_servers = m_proxy_servers;
} }
@ -594,52 +594,52 @@ namespace mamba
TEST_CASE_FIXTURE(Configuration, "ssl_verify") TEST_CASE_FIXTURE(Configuration, "ssl_verify")
{ {
// Default empty string value // Default empty string value
ctx.ssl_verify = ""; ctx.remote_fetch_params.ssl_verify = "";
std::string rc = ""; std::string rc = "";
load_test_config(rc); load_test_config(rc);
CHECK_EQ(ctx.ssl_verify, "<system>"); CHECK_EQ(ctx.remote_fetch_params.ssl_verify, "<system>");
rc = "ssl_verify: true"; rc = "ssl_verify: true";
load_test_config(rc); load_test_config(rc);
CHECK_EQ(ctx.ssl_verify, "<system>"); CHECK_EQ(ctx.remote_fetch_params.ssl_verify, "<system>");
rc = "ssl_verify: <true>"; rc = "ssl_verify: <true>";
load_test_config(rc); load_test_config(rc);
CHECK_EQ(ctx.ssl_verify, "<system>"); CHECK_EQ(ctx.remote_fetch_params.ssl_verify, "<system>");
rc = "ssl_verify: 1"; rc = "ssl_verify: 1";
load_test_config(rc); load_test_config(rc);
CHECK_EQ(ctx.ssl_verify, "<system>"); CHECK_EQ(ctx.remote_fetch_params.ssl_verify, "<system>");
rc = "ssl_verify: 10"; rc = "ssl_verify: 10";
load_test_config(rc); load_test_config(rc);
CHECK_EQ(ctx.ssl_verify, "10"); CHECK_EQ(ctx.remote_fetch_params.ssl_verify, "10");
rc = "ssl_verify: false"; rc = "ssl_verify: false";
load_test_config(rc); load_test_config(rc);
CHECK_EQ(ctx.ssl_verify, "<false>"); CHECK_EQ(ctx.remote_fetch_params.ssl_verify, "<false>");
rc = "ssl_verify: <false>"; rc = "ssl_verify: <false>";
load_test_config(rc); load_test_config(rc);
CHECK_EQ(ctx.ssl_verify, "<false>"); CHECK_EQ(ctx.remote_fetch_params.ssl_verify, "<false>");
rc = "ssl_verify: 0"; rc = "ssl_verify: 0";
load_test_config(rc); load_test_config(rc);
CHECK_EQ(ctx.ssl_verify, "<false>"); CHECK_EQ(ctx.remote_fetch_params.ssl_verify, "<false>");
rc = "ssl_verify: /foo/bar/baz"; rc = "ssl_verify: /foo/bar/baz";
load_test_config(rc); load_test_config(rc);
CHECK_EQ(ctx.ssl_verify, "/foo/bar/baz"); CHECK_EQ(ctx.remote_fetch_params.ssl_verify, "/foo/bar/baz");
std::string rc1 = "ssl_verify: true"; std::string rc1 = "ssl_verify: true";
std::string rc2 = "ssl_verify: false"; std::string rc2 = "ssl_verify: false";
load_test_config({ rc1, rc2 }); load_test_config({ rc1, rc2 });
CHECK_EQ(config.at("ssl_verify").value<std::string>(), "<system>"); CHECK_EQ(config.at("ssl_verify").value<std::string>(), "<system>");
CHECK_EQ(ctx.ssl_verify, "<system>"); CHECK_EQ(ctx.remote_fetch_params.ssl_verify, "<system>");
load_test_config({ rc2, rc1 }); load_test_config({ rc2, rc1 });
CHECK_EQ(config.at("ssl_verify").value<std::string>(), "<false>"); CHECK_EQ(config.at("ssl_verify").value<std::string>(), "<false>");
CHECK_EQ(ctx.ssl_verify, "<false>"); CHECK_EQ(ctx.remote_fetch_params.ssl_verify, "<false>");
env::set("MAMBA_SSL_VERIFY", "/env/bar/baz"); env::set("MAMBA_SSL_VERIFY", "/env/bar/baz");
load_test_config(rc1); load_test_config(rc1);
@ -669,7 +669,7 @@ namespace mamba
load_test_config(rc); load_test_config(rc);
CHECK_EQ(config.at("ssl_verify").value<std::string>(), "/other/foo/bar/baz"); CHECK_EQ(config.at("ssl_verify").value<std::string>(), "/other/foo/bar/baz");
CHECK_EQ(config.at("cacert_path").value<std::string>(), "/other/foo/bar/baz"); CHECK_EQ(config.at("cacert_path").value<std::string>(), "/other/foo/bar/baz");
CHECK_EQ(ctx.ssl_verify, "/other/foo/bar/baz"); CHECK_EQ(ctx.remote_fetch_params.ssl_verify, "/other/foo/bar/baz");
env::set("MAMBA_CACERT_PATH", "/env/ca/baz"); env::set("MAMBA_CACERT_PATH", "/env/ca/baz");
load_test_config(rc); load_test_config(rc);
@ -687,7 +687,7 @@ namespace mamba
+ src + "'") + src + "'")
.c_str()) .c_str())
); );
CHECK_EQ(ctx.ssl_verify, "/env/ca/baz"); CHECK_EQ(ctx.remote_fetch_params.ssl_verify, "/env/ca/baz");
config.at("cacert_path").set_yaml_value("/new/test").compute(); config.at("cacert_path").set_yaml_value("/new/test").compute();
CHECK_EQ( CHECK_EQ(
@ -699,7 +699,7 @@ namespace mamba
+ src + "'") + src + "'")
.c_str()) .c_str())
); );
CHECK_EQ(ctx.ssl_verify, "/env/ca/baz"); CHECK_EQ(ctx.remote_fetch_params.ssl_verify, "/env/ca/baz");
config.at("ssl_verify").compute(); config.at("ssl_verify").compute();
CHECK_EQ( CHECK_EQ(
@ -711,7 +711,7 @@ namespace mamba
+ src + "'") + src + "'")
.c_str()) .c_str())
); );
CHECK_EQ(ctx.ssl_verify, "/new/test"); CHECK_EQ(ctx.remote_fetch_params.ssl_verify, "/new/test");
env::unset("MAMBA_CACERT_PATH"); env::unset("MAMBA_CACERT_PATH");
load_test_config("cacert_path:\nssl_verify: true"); // reset ssl verify to default load_test_config("cacert_path:\nssl_verify: true"); // reset ssl verify to default
@ -827,7 +827,7 @@ namespace mamba
load_test_config(rc2); \ load_test_config(rc2); \
} }
TEST_BOOL_CONFIGURABLE(ssl_no_revoke, ctx.ssl_no_revoke); TEST_BOOL_CONFIGURABLE(ssl_no_revoke, ctx.remote_fetch_params.ssl_no_revoke);
TEST_BOOL_CONFIGURABLE(override_channels_enabled, ctx.override_channels_enabled); TEST_BOOL_CONFIGURABLE(override_channels_enabled, ctx.override_channels_enabled);

View File

@ -25,7 +25,7 @@ namespace mamba
{ {
// TEST(cpp_install, install) // TEST(cpp_install, install)
// { // {
// Context::instance().verbosity = 3; // Context::instance().output_params.verbosity = 3;
// PackageInfo pkg("wheel", "0.34.2", "py_1", 1); // PackageInfo pkg("wheel", "0.34.2", "py_1", 1);
// fs::u8path prefix = "C:\\Users\\wolfv\\miniconda3\\"; // fs::u8path prefix = "C:\\Users\\wolfv\\miniconda3\\";
// TransactionContext tc(prefix, "3.8.x"); // TransactionContext tc(prefix, "3.8.x");

View File

@ -15,12 +15,12 @@ namespace mamba
{ {
TEST_CASE("no_progress_bars") TEST_CASE("no_progress_bars")
{ {
Context::instance().no_progress_bars = true; Context::instance().graphics_params.no_progress_bars = true;
auto proxy = Console::instance().add_progress_bar("conda-forge"); auto proxy = Console::instance().add_progress_bar("conda-forge");
CHECK_FALSE(proxy.defined()); CHECK_FALSE(proxy.defined());
CHECK_FALSE(proxy); CHECK_FALSE(proxy);
Context::instance().no_progress_bars = false; Context::instance().graphics_params.no_progress_bars = false;
proxy = Console::instance().add_progress_bar("conda-forge"); proxy = Console::instance().add_progress_bar("conda-forge");
CHECK(proxy.defined()); CHECK(proxy.defined());
CHECK(proxy); CHECK(proxy);

View File

@ -353,10 +353,10 @@ namespace mamba
auto cache = MultiPackageCache({ tmp_dir.path / "cache" }); auto cache = MultiPackageCache({ tmp_dir.path / "cache" });
create_cache_dir(cache.first_writable_path()); create_cache_dir(cache.first_writable_path());
bool prev_progress_bars_value = Context::instance().no_progress_bars; bool prev_progress_bars_value = Context::instance().graphics_params.no_progress_bars;
Context::instance().no_progress_bars = true; Context::instance().graphics_params.no_progress_bars = true;
load_channels(pool, cache, make_platform_channels(std::move(channels), platforms)); load_channels(pool, cache, make_platform_channels(std::move(channels), platforms));
Context::instance().no_progress_bars = prev_progress_bars_value; Context::instance().graphics_params.no_progress_bars = prev_progress_bars_value;
auto solver = std::make_unique<MSolver>( auto solver = std::make_unique<MSolver>(
std::move(pool), std::move(pool),

View File

@ -24,7 +24,7 @@ namespace mamba
{ {
int res = 0; int res = 0;
// Ensures the compiler doe snot optimize away Context::instance() // Ensures the compiler doe snot optimize away Context::instance()
std::string current_command = Context::instance().current_command; std::string current_command = Context::instance().command_params.current_command;
CHECK_EQ(current_command, "mamba"); CHECK_EQ(current_command, "mamba");
Console::instance().init_progress_bar_manager(ProgressBarMode::multi); Console::instance().init_progress_bar_manager(ProgressBarMode::multi);
{ {

View File

@ -17,7 +17,7 @@ namespace mamba
TEST_CASE("file_not_exist") TEST_CASE("file_not_exist")
{ {
#ifdef __linux__ #ifdef __linux__
Context::instance().quiet = true; Context::instance().output_params.quiet = true;
{ {
const mamba::Channel& c = mamba::make_channel("conda-forge"); const mamba::Channel& c = mamba::make_channel("conda-forge");
mamba::MultiDownloadTarget multi_dl; mamba::MultiDownloadTarget multi_dl;
@ -53,7 +53,7 @@ namespace mamba
multi_dl.add(cf.target()); multi_dl.add(cf.target());
CHECK_THROWS_AS(multi_dl.download(MAMBA_DOWNLOAD_FAILFAST), std::runtime_error); CHECK_THROWS_AS(multi_dl.download(MAMBA_DOWNLOAD_FAILFAST), std::runtime_error);
} }
Context::instance().quiet = false; Context::instance().output_params.quiet = false;
#endif #endif
} }
} }

View File

@ -394,6 +394,85 @@ class Configuration:
pass pass
class Context: class Context:
class OutputParams:
def __init__(self) -> None: ...
@property
def json(self) -> bool:
"""
:type: bool
"""
@json.setter
def json(self, arg0: bool) -> None:
pass
@property
def quiet(self) -> bool:
"""
:type: bool
"""
@quiet.setter
def quiet(self, arg0: bool) -> None:
pass
@property
def verbosity(self) -> int:
"""
:type: int
"""
@verbosity.setter
def verbosity(self, arg0: int) -> None:
pass
pass
class RemoteFetchParams:
def __init__(self) -> None: ...
@property
def connect_timeout_secs(self) -> int:
"""
:type: int
"""
@connect_timeout_secs.setter
def connect_timeout_secs(self, arg0: int) -> None:
pass
@property
def max_retries(self) -> int:
"""
:type: int
"""
@max_retries.setter
def max_retries(self, arg0: int) -> None:
pass
@property
def retry_backoff(self) -> int:
"""
:type: int
"""
@retry_backoff.setter
def retry_backoff(self, arg0: int) -> None:
pass
@property
def retry_timeout(self) -> int:
"""
:type: int
"""
@retry_timeout.setter
def retry_timeout(self, arg0: int) -> None:
pass
@property
def ssl_verify(self) -> str:
"""
:type: str
"""
@ssl_verify.setter
def ssl_verify(self, arg0: str) -> None:
pass
@property
def user_agent(self) -> str:
"""
:type: str
"""
@user_agent.setter
def user_agent(self, arg0: str) -> None:
pass
pass
def __init__(self) -> None: ... def __init__(self) -> None: ...
def set_log_level(self, arg0: LogLevel) -> None: ... def set_log_level(self, arg0: LogLevel) -> None: ...
def set_verbosity(self, arg0: int) -> None: ... def set_verbosity(self, arg0: int) -> None: ...
@ -446,14 +525,6 @@ class Context:
def conda_prefix(self, arg0: Path) -> None: def conda_prefix(self, arg0: Path) -> None:
pass pass
@property @property
def connect_timeout_secs(self) -> int:
"""
:type: int
"""
@connect_timeout_secs.setter
def connect_timeout_secs(self, arg0: int) -> None:
pass
@property
def custom_channels(self) -> typing.Dict[str, str]: def custom_channels(self) -> typing.Dict[str, str]:
""" """
:type: typing.Dict[str, str] :type: typing.Dict[str, str]
@ -526,14 +597,6 @@ class Context:
def extract_threads(self, arg0: int) -> None: def extract_threads(self, arg0: int) -> None:
pass pass
@property @property
def json(self) -> bool:
"""
:type: bool
"""
@json.setter
def json(self, arg0: bool) -> None:
pass
@property
def local_repodata_ttl(self) -> int: def local_repodata_ttl(self) -> int:
""" """
:type: int :type: int
@ -542,14 +605,6 @@ class Context:
def local_repodata_ttl(self, arg0: int) -> None: def local_repodata_ttl(self, arg0: int) -> None:
pass pass
@property @property
def max_retries(self) -> int:
"""
:type: int
"""
@max_retries.setter
def max_retries(self, arg0: int) -> None:
pass
@property
def offline(self) -> bool: def offline(self) -> bool:
""" """
:type: bool :type: bool
@ -558,6 +613,14 @@ class Context:
def offline(self, arg0: bool) -> None: def offline(self, arg0: bool) -> None:
pass pass
@property @property
def output_params(self) -> Context.OutputParams:
"""
:type: Context.OutputParams
"""
@output_params.setter
def output_params(self, arg0: Context.OutputParams) -> None:
pass
@property
def pkgs_dirs(self) -> typing.List[Path]: def pkgs_dirs(self) -> typing.List[Path]:
""" """
:type: typing.List[Path] :type: typing.List[Path]
@ -582,28 +645,12 @@ class Context:
def proxy_servers(self, arg0: typing.Dict[str, str]) -> None: def proxy_servers(self, arg0: typing.Dict[str, str]) -> None:
pass pass
@property @property
def quiet(self) -> bool: def remote_fetch_params(self) -> Context.RemoteFetchParams:
""" """
:type: bool :type: Context.RemoteFetchParams
""" """
@quiet.setter @remote_fetch_params.setter
def quiet(self, arg0: bool) -> None: def remote_fetch_params(self, arg0: Context.RemoteFetchParams) -> None:
pass
@property
def retry_backoff(self) -> int:
"""
:type: int
"""
@retry_backoff.setter
def retry_backoff(self, arg0: int) -> None:
pass
@property
def retry_timeout(self) -> int:
"""
:type: int
"""
@retry_timeout.setter
def retry_timeout(self, arg0: int) -> None:
pass pass
@property @property
def root_prefix(self) -> Path: def root_prefix(self) -> Path:
@ -614,14 +661,6 @@ class Context:
def root_prefix(self, arg0: Path) -> None: def root_prefix(self, arg0: Path) -> None:
pass pass
@property @property
def ssl_verify(self) -> str:
"""
:type: str
"""
@ssl_verify.setter
def ssl_verify(self, arg0: str) -> None:
pass
@property
def target_prefix(self) -> Path: def target_prefix(self) -> Path:
""" """
:type: Path :type: Path
@ -653,22 +692,6 @@ class Context:
@use_only_tar_bz2.setter @use_only_tar_bz2.setter
def use_only_tar_bz2(self, arg0: bool) -> None: def use_only_tar_bz2(self, arg0: bool) -> None:
pass pass
@property
def user_agent(self) -> str:
"""
:type: str
"""
@user_agent.setter
def user_agent(self, arg0: str) -> None:
pass
@property
def verbosity(self) -> int:
"""
:type: int
"""
@verbosity.setter
def verbosity(self, arg0: int) -> None:
pass
pass pass
class DownloadTargetList: class DownloadTargetList:

View File

@ -507,11 +507,8 @@ PYBIND11_MODULE(bindings, m)
.value("CRITICAL", mamba::log_level::critical) .value("CRITICAL", mamba::log_level::critical)
.value("OFF", mamba::log_level::off); .value("OFF", mamba::log_level::off);
py::class_<Context, std::unique_ptr<Context, py::nodelete>>(m, "Context") py::class_<Context, std::unique_ptr<Context, py::nodelete>> ctx(m, "Context");
.def(py::init([]() { return std::unique_ptr<Context, py::nodelete>(&Context::instance()); })) ctx.def(py::init([]() { return std::unique_ptr<Context, py::nodelete>(&Context::instance()); }))
.def_readwrite("verbosity", &Context::verbosity)
.def_readwrite("quiet", &Context::quiet)
.def_readwrite("json", &Context::json)
.def_readwrite("offline", &Context::offline) .def_readwrite("offline", &Context::offline)
.def_readwrite("local_repodata_ttl", &Context::local_repodata_ttl) .def_readwrite("local_repodata_ttl", &Context::local_repodata_ttl)
.def_readwrite("use_index_cache", &Context::use_index_cache) .def_readwrite("use_index_cache", &Context::use_index_cache)
@ -520,14 +517,7 @@ PYBIND11_MODULE(bindings, m)
.def_readwrite("always_yes", &Context::always_yes) .def_readwrite("always_yes", &Context::always_yes)
.def_readwrite("dry_run", &Context::dry_run) .def_readwrite("dry_run", &Context::dry_run)
.def_readwrite("download_only", &Context::download_only) .def_readwrite("download_only", &Context::download_only)
.def_readwrite("ssl_verify", &Context::ssl_verify)
.def_readwrite("proxy_servers", &Context::proxy_servers) .def_readwrite("proxy_servers", &Context::proxy_servers)
.def_readwrite("max_retries", &Context::max_retries)
.def_readwrite("retry_timeout", &Context::retry_timeout)
.def_readwrite("retry_backoff", &Context::retry_backoff)
.def_readwrite("user_agent", &Context::user_agent)
// .def_readwrite("read_timeout_secs", &Context::read_timeout_secs)
.def_readwrite("connect_timeout_secs", &Context::connect_timeout_secs)
.def_readwrite("add_pip_as_python_dependency", &Context::add_pip_as_python_dependency) .def_readwrite("add_pip_as_python_dependency", &Context::add_pip_as_python_dependency)
.def_readwrite("target_prefix", &Context::target_prefix) .def_readwrite("target_prefix", &Context::target_prefix)
.def_readwrite("conda_prefix", &Context::conda_prefix) .def_readwrite("conda_prefix", &Context::conda_prefix)
@ -559,6 +549,25 @@ PYBIND11_MODULE(bindings, m)
.def("set_verbosity", &Context::set_verbosity) .def("set_verbosity", &Context::set_verbosity)
.def("set_log_level", &Context::set_log_level); .def("set_log_level", &Context::set_log_level);
py::class_<Context::RemoteFetchParams>(ctx, "RemoteFetchParams")
.def(py::init<>())
.def_readwrite("ssl_verify", &Context::RemoteFetchParams::ssl_verify)
.def_readwrite("max_retries", &Context::RemoteFetchParams::max_retries)
.def_readwrite("retry_timeout", &Context::RemoteFetchParams::retry_timeout)
.def_readwrite("retry_backoff", &Context::RemoteFetchParams::retry_backoff)
.def_readwrite("user_agent", &Context::RemoteFetchParams::user_agent)
// .def_readwrite("read_timeout_secs", &Context::RemoteFetchParams::read_timeout_secs)
.def_readwrite("connect_timeout_secs", &Context::RemoteFetchParams::connect_timeout_secs);
py::class_<Context::OutputParams>(ctx, "OutputParams")
.def(py::init<>())
.def_readwrite("verbosity", &Context::OutputParams::verbosity)
.def_readwrite("json", &Context::OutputParams::json)
.def_readwrite("quiet", &Context::OutputParams::quiet);
ctx.def_readwrite("remote_fetch_params", &Context::remote_fetch_params)
.def_readwrite("output_params", &Context::output_params);
pyPrefixData pyPrefixData
.def(py::init( .def(py::init(
[](const fs::u8path& prefix_path) -> PrefixData [](const fs::u8path& prefix_path) -> PrefixData

View File

@ -196,7 +196,7 @@ def log_level_from_verbosity(verbosity: int):
def init_api_context(use_mamba_experimental=False): def init_api_context(use_mamba_experimental=False):
api_ctx = api.Context() api_ctx = api.Context()
api_ctx.json = context.json api_ctx.output_params.json = context.json
api_ctx.dry_run = context.dry_run api_ctx.dry_run = context.dry_run
if context.json: if context.json:
context.always_yes = True context.always_yes = True
@ -204,9 +204,9 @@ def init_api_context(use_mamba_experimental=False):
if use_mamba_experimental: if use_mamba_experimental:
context.json = False context.json = False
api_ctx.verbosity = context.verbosity api_ctx.output_params.verbosity = context.verbosity
api_ctx.set_verbosity(context.verbosity) api_ctx.set_verbosity(context.verbosity)
api_ctx.quiet = context.quiet api_ctx.output_params.quiet = context.quiet
api_ctx.offline = context.offline api_ctx.offline = context.offline
api_ctx.local_repodata_ttl = context.local_repodata_ttl api_ctx.local_repodata_ttl = context.local_repodata_ttl
api_ctx.use_index_cache = context.use_index_cache api_ctx.use_index_cache = context.use_index_cache
@ -260,18 +260,20 @@ def init_api_context(use_mamba_experimental=False):
] ]
if context.ssl_verify is False: if context.ssl_verify is False:
api_ctx.ssl_verify = "<false>" api_ctx.remote_fetch_params.ssl_verify = "<false>"
elif context.ssl_verify is not True: elif context.ssl_verify is not True:
api_ctx.ssl_verify = context.ssl_verify api_ctx.remote_fetch_params.ssl_verify = context.ssl_verify
api_ctx.target_prefix = context.target_prefix api_ctx.target_prefix = context.target_prefix
api_ctx.root_prefix = context.root_prefix api_ctx.root_prefix = context.root_prefix
api_ctx.conda_prefix = context.conda_prefix api_ctx.conda_prefix = context.conda_prefix
api_ctx.pkgs_dirs = context.pkgs_dirs api_ctx.pkgs_dirs = context.pkgs_dirs
api_ctx.envs_dirs = context.envs_dirs api_ctx.envs_dirs = context.envs_dirs
api_ctx.connect_timeout_secs = int(round(context.remote_connect_timeout_secs)) api_ctx.remote_fetch_params.connect_timeout_secs = int(
api_ctx.max_retries = context.remote_max_retries round(context.remote_connect_timeout_secs)
api_ctx.retry_backoff = context.remote_backoff_factor )
api_ctx.remote_fetch_params.max_retries = context.remote_max_retries
api_ctx.remote_fetch_params.retry_backoff = context.remote_backoff_factor
api_ctx.add_pip_as_python_dependency = context.add_pip_as_python_dependency api_ctx.add_pip_as_python_dependency = context.add_pip_as_python_dependency
api_ctx.use_only_tar_bz2 = context.use_only_tar_bz2 api_ctx.use_only_tar_bz2 = context.use_only_tar_bz2

View File

@ -160,7 +160,7 @@ set_env_command(CLI::App* com)
EnvironmentsManager env_manager; EnvironmentsManager env_manager;
if (ctx.json) if (ctx.output_params.json)
{ {
nlohmann::json res; nlohmann::json res;
const auto pfxs = env_manager.list_all_known_prefixes(); const auto pfxs = env_manager.list_all_known_prefixes();

View File

@ -38,8 +38,8 @@ main(int argc, char** argv)
init_console(); init_console();
auto& ctx = Context::instance(); auto& ctx = Context::instance();
ctx.is_micromamba = true; ctx.command_params.is_micromamba = true;
ctx.custom_banner = banner; ctx.command_params.custom_banner = banner;
CLI::App app{ "Version: " + version() + "\n" }; CLI::App app{ "Version: " + version() + "\n" };
set_umamba_command(&app); set_umamba_command(&app);
@ -81,7 +81,7 @@ main(int argc, char** argv)
full_command << " "; full_command << " ";
} }
} }
ctx.current_command = full_command.str(); ctx.command_params.current_command = full_command.str();
std::optional<std::string> error_to_report; std::optional<std::string> error_to_report;
try try

View File

@ -25,7 +25,7 @@ set_umamba_command(CLI::App* com)
{ {
init_umamba_options(com); init_umamba_options(com);
Context::instance().caller_version = umamba::version(); Context::instance().command_params.caller_version = umamba::version();
auto print_version = [](int /*count*/) auto print_version = [](int /*count*/)
{ {