No Singleton: `Configuration` (#2541)

* Removed unused debugging macros.

* mamba::Configuration is not a singleton anymore.

* review fix
This commit is contained in:
Klaim (Joël Lamotte) 2023-06-15 11:41:21 +02:00 committed by GitHub
parent 4aea24f584
commit ec95d18986
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
48 changed files with 592 additions and 573 deletions

View File

@ -7,32 +7,40 @@
#ifndef MAMBA_API_C_API_H
#define MAMBA_API_C_API_H
namespace mamba
{
class Configuration;
}
#ifdef __cplusplus
extern "C"
{
#endif
int mamba_create();
mamba::Configuration* mamba_new_configuration();
void mamba_delete_configuration(mamba::Configuration* config);
int mamba_install();
int mamba_create(mamba::Configuration* config);
int mamba_update(int update_all = 0);
int mamba_install(mamba::Configuration* config);
int mamba_remove(int remove_all = 0);
int mamba_update(mamba::Configuration* config, int update_all = 0);
int mamba_list(const char* regex = "");
int mamba_remove(mamba::Configuration* config, int remove_all = 0);
int mamba_info();
int mamba_list(mamba::Configuration* config, const char* regex = "");
int mamba_config_list();
int mamba_info(mamba::Configuration* config);
int mamba_set_cli_config(const char* name, const char* value);
int mamba_config_list(mamba::Configuration* config);
int mamba_set_config(const char* name, const char* value);
int mamba_set_cli_config(mamba::Configuration* config, const char* name, const char* value);
int mamba_clear_config(const char* name);
int mamba_set_config(mamba::Configuration* config, const char* name, const char* value);
int mamba_use_conda_root_prefix(int force = 0);
int mamba_clear_config(mamba::Configuration* config, const char* name);
int mamba_use_conda_root_prefix(mamba::Configuration* config, int force = 0);
#ifdef __cplusplus
}

View File

@ -18,7 +18,8 @@ namespace mamba
const int MAMBA_CLEAN_TRASH = 1 << 5;
const int MAMBA_CLEAN_FORCE_PKGS_DIRS = 1 << 6;
void clean(int options);
class Configuration;
void clean(Configuration& config, int options);
}
#endif

View File

@ -10,11 +10,13 @@
namespace mamba
{
void config_describe();
class Configuration;
void config_list();
void config_describe(Configuration& config);
void config_sources();
void config_list(Configuration& config);
void config_sources(Configuration& config);
}
#endif

View File

@ -19,22 +19,10 @@
#include "mamba/core/output.hpp"
#define CONTEXT_DEBUGGING \
if (Configuration::instance().at("print_context_only").value<bool>()) \
{ \
Context::instance().debug_print(); \
exit(0); \
}
#define CONFIG_DEBUGGING \
if (Configuration::instance().at("print_config_only").value<bool>()) \
{ \
int dump_opts = MAMBA_SHOW_CONFIG_VALUES | MAMBA_SHOW_CONFIG_SRCS | MAMBA_SHOW_ALL_CONFIGS; \
std::cout << Configuration::instance().dump(dump_opts) << std::endl; \
exit(0); \
}
namespace mamba
{
class Configuration;
enum class ConfigurationLevel
{
kApi = 0,
@ -149,10 +137,13 @@ namespace mamba
virtual YAML::Node yaml_value() const = 0;
virtual void dump_json(nlohmann::json& node, const std::string& name) const = 0;
bool is_config_loading() const;
std::string m_name;
std::string m_group = "Default";
std::string m_description = "No description provided";
std::string m_long_description = "";
Configuration* m_config = nullptr;
std::vector<std::string> m_rc_sources;
std::vector<std::string> m_sources;
@ -364,6 +355,12 @@ namespace mamba
YAML::Node yaml_value() const;
void dump_json(nlohmann::json& node, const std::string& name) const;
void set_configuration(Configuration& config)
{
p_impl->m_config = &config;
assert(p_impl->m_config);
}
private:
template <class T>
@ -391,16 +388,20 @@ namespace mamba
{
public:
static Configuration& instance();
Configuration();
~Configuration();
std::map<std::string, Configurable>& config();
const std::map<std::string, Configurable>& config() const;
Configurable& at(const std::string& name);
const Configurable& at(const std::string& name) const;
using grouped_config_type = std::pair<std::string, std::vector<Configurable*>>;
std::vector<grouped_config_type> get_grouped_config();
using grouped_config_type = std::pair<std::string, std::vector<const Configurable*>>;
std::vector<grouped_config_type> get_grouped_config() const;
std::vector<fs::u8path> sources();
std::vector<fs::u8path> valid_sources();
std::vector<fs::u8path> sources() const;
std::vector<fs::u8path> valid_sources() const;
void set_rc_values(std::vector<fs::u8path> possible_rc_paths, const RCConfigLevel& level);
@ -422,17 +423,13 @@ namespace mamba
*/
void operation_teardown();
std::string dump(int opts = MAMBA_SHOW_CONFIG_VALUES, std::vector<std::string> names = {});
std::string
dump(int opts = MAMBA_SHOW_CONFIG_VALUES, std::vector<std::string> names = {}) const;
Configurable& insert(Configurable configurable, bool allow_redefinition = false);
void reset_configurables();
protected:
Configuration();
~Configuration();
protected:
Configuration(const Configuration&) = delete;
@ -659,7 +656,7 @@ namespace mamba
LOG_TRACE << "Compute configurable '" << this->m_name << "'";
}
if (!force_compute && (Configuration::instance().is_loading() && (m_compute_counter > 0)))
if (!force_compute && ((is_config_loading() && (m_compute_counter > 0))))
{
throw std::runtime_error(
"Multiple computation of '" + m_name + "' detected during loading sequence."
@ -790,7 +787,7 @@ namespace mamba
template <class T>
T& Configurable::value()
{
if (Configuration::instance().is_loading() && p_impl->m_compute_counter == 0)
if (p_impl->is_config_loading() && p_impl->m_compute_counter == 0)
{
throw std::runtime_error("Using '" + name() + "' value without previous computation.");
}
@ -929,7 +926,8 @@ namespace mamba
std::string name = configurable.name();
if (m_config.count(name) == 0)
{
m_config.insert({ name, std::move(configurable) });
auto [it, success] = m_config.insert({ name, std::move(configurable) });
it->second.set_configuration(*this);
m_config_order.push_back(name);
}
else
@ -943,7 +941,7 @@ namespace mamba
return m_config.at(name);
}
void use_conda_root_prefix(bool force = false);
void use_conda_root_prefix(Configuration& config, bool force = false);
}
#endif // MAMBA_CONFIG_HPP

View File

@ -13,7 +13,9 @@
namespace mamba
{
void create();
class Configuration;
void create(Configuration& config);
namespace detail
{

View File

@ -17,8 +17,9 @@
namespace mamba
{
class ChannelContext;
class Configuration;
void info();
void info(Configuration& config);
std::string version();
std::string banner();
@ -36,7 +37,7 @@ namespace mamba
namespace detail
{
void print_info(ChannelContext& channel_context);
void print_info(ChannelContext& channel_context, const Configuration& config);
}
}

View File

@ -25,11 +25,13 @@
namespace mamba
{
class ChannelContext;
class Configuration;
void install();
void install(Configuration& config);
void install_specs(
ChannelContext& channel_context,
const Configuration& config,
const std::vector<std::string>& specs,
bool create_env = false,
int solver_flag = SOLVER_INSTALL,
@ -54,9 +56,9 @@ namespace mamba
void create_empty_target(const fs::u8path& prefix);
void file_specs_hook(std::vector<std::string>& file_specs);
void file_specs_hook(Configuration& config, std::vector<std::string>& file_specs);
void channels_hook(std::vector<std::string>& channels);
void channels_hook(Configuration& config, std::vector<std::string>& channels);
bool download_explicit(const std::vector<PackageInfo>& pkgs, MultiPackageCache& pkg_caches);

View File

@ -12,8 +12,9 @@
namespace mamba
{
class ChannelContext;
class Configuration;
void list(const std::string& regex);
void list(Configuration& config, const std::string& regex);
namespace detail
{

View File

@ -16,7 +16,7 @@ namespace mamba
{
class ChannelContext;
void remove(int flags = MAMBA_REMOVE_PRUNE);
void remove(Configuration& config, int flags = MAMBA_REMOVE_PRUNE);
namespace detail
{

View File

@ -8,6 +8,11 @@
namespace mamba
{
void
repoquery(QueryType type, QueryResultFormat format, bool use_local, const std::string& query);
void repoquery(
Configuration& config,
QueryType type,
QueryResultFormat format,
bool use_local,
const std::string& query
);
}

View File

@ -16,7 +16,7 @@
namespace mamba
{
void update(bool update_all = false, bool prune = false);
void update(Configuration& config, bool update_all = false, bool prune = false);
}
#endif

View File

@ -4,6 +4,7 @@
//
// The full license is in the file LICENSE, distributed with this software.
#include <cassert>
#include <string>
#include "mamba/api/c_api.h"
@ -16,170 +17,191 @@
#include "mamba/api/remove.hpp"
#include "mamba/api/update.hpp"
using namespace mamba;
mamba::Configuration*
mamba_new_configuration()
{
return new mamba::Configuration;
}
void
mamba_delete_configuration(mamba::Configuration* config)
{
delete config;
}
int
mamba_create()
mamba_create(mamba::Configuration* config)
{
assert(config != nullptr);
try
{
create();
create(*config);
return 0;
}
catch (...)
{
Configuration::instance().operation_teardown();
config->operation_teardown();
return 1;
}
}
int
mamba_install()
mamba_install(mamba::Configuration* config)
{
assert(config != nullptr);
try
{
install();
install(*config);
return 0;
}
catch (...)
{
Configuration::instance().operation_teardown();
config->operation_teardown();
return 1;
}
}
int
mamba_update(int update_all)
mamba_update(mamba::Configuration* config, int update_all)
{
assert(config != nullptr);
try
{
update(update_all);
update(*config, update_all);
return 0;
}
catch (...)
{
Configuration::instance().operation_teardown();
config->operation_teardown();
return 1;
}
}
int
mamba_remove(int remove_all)
mamba_remove(mamba::Configuration* config, int remove_all)
{
assert(config != nullptr);
try
{
remove(remove_all);
remove(*config, remove_all);
return 0;
}
catch (...)
{
Configuration::instance().operation_teardown();
config->operation_teardown();
return 1;
}
}
int
mamba_list(const char* regex)
mamba_list(mamba::Configuration* config, const char* regex)
{
assert(config != nullptr);
try
{
list(regex);
list(*config, regex);
return 0;
}
catch (...)
{
Configuration::instance().operation_teardown();
config->operation_teardown();
return 1;
}
}
int
mamba_info()
mamba_info(mamba::Configuration* config)
{
assert(config != nullptr);
try
{
info();
info(*config);
return 0;
}
catch (...)
{
Configuration::instance().operation_teardown();
config->operation_teardown();
return 1;
}
}
int
mamba_config_list()
mamba_config_list(mamba::Configuration* config)
{
assert(config != nullptr);
try
{
config_list();
config_list(*config);
return 0;
}
catch (...)
{
Configuration::instance().operation_teardown();
config->operation_teardown();
return 1;
}
}
int
mamba_set_cli_config(const char* name, const char* value)
mamba_set_cli_config(mamba::Configuration* config, const char* name, const char* value)
{
assert(config != nullptr);
try
{
Configuration::instance().at(name).set_cli_yaml_value(value);
config->at(name).set_cli_yaml_value(value);
return 0;
}
catch (...)
{
Configuration::instance().operation_teardown();
config->operation_teardown();
return 1;
}
}
int
mamba_set_config(const char* name, const char* value)
mamba_set_config(mamba::Configuration* config, const char* name, const char* value)
{
assert(config != nullptr);
try
{
Configuration::instance().at(name).set_yaml_value(value);
config->at(name).set_yaml_value(value);
return 0;
}
catch (...)
{
Configuration::instance().operation_teardown();
config->operation_teardown();
return 1;
}
}
int
mamba_clear_config(const char* name)
mamba_clear_config(mamba::Configuration* config, const char* name)
{
assert(config != nullptr);
try
{
Configuration::instance().at(name).clear_values();
config->at(name).clear_values();
return 0;
}
catch (...)
{
Configuration::instance().operation_teardown();
config->operation_teardown();
return 1;
}
}
int
mamba_use_conda_root_prefix(int force)
mamba_use_conda_root_prefix(mamba::Configuration* config, int force)
{
assert(config != nullptr);
try
{
use_conda_root_prefix(force);
use_conda_root_prefix(*config, force);
return 0;
}
catch (...)
{
Configuration::instance().operation_teardown();
config->operation_teardown();
return 1;
}
}

View File

@ -18,10 +18,9 @@
namespace mamba
{
void clean(int options)
void clean(Configuration& config, int options)
{
auto& ctx = Context::instance();
auto& config = Configuration::instance();
config.at("use_target_prefix_fallback").set_value(true);
config.load();
@ -313,7 +312,5 @@ namespace mamba
fs::remove_all(cache->path());
}
}
config.operation_teardown();
}
} // mamba

View File

@ -11,10 +11,8 @@
namespace mamba
{
void config_describe()
void config_describe(Configuration& config)
{
auto& config = Configuration::instance();
config.at("use_target_prefix_fallback").set_value(true);
config.at("show_banner").set_value(false);
config.at("target_prefix_checks")
@ -37,10 +35,8 @@ namespace mamba
config.operation_teardown();
}
void config_list()
void config_list(Configuration& config)
{
auto& config = Configuration::instance();
config.at("use_target_prefix_fallback").set_value(true);
config.at("show_banner").set_value(false);
config.at("target_prefix_checks")
@ -71,10 +67,8 @@ namespace mamba
config.operation_teardown();
}
void config_sources()
void config_sources(Configuration& config)
{
auto& config = Configuration::instance();
config.at("use_target_prefix_fallback").set_value(true);
config.at("show_banner").set_value(false);
config.at("target_prefix_checks")
@ -110,7 +104,5 @@ namespace mamba
}
}
}
config.operation_teardown();
}
}

View File

@ -55,6 +55,12 @@ namespace mamba
{
return m_rc_configured && !Context::instance().src_params.no_rc;
}
bool ConfigurableImplBase::is_config_loading() const
{
return m_config == nullptr || m_config->is_loading();
}
}
/*******************************
@ -383,9 +389,9 @@ namespace mamba
namespace detail
{
void ssl_verify_hook(std::string& value)
void ssl_verify_hook(Configuration& config, std::string& value)
{
bool& offline = Configuration::instance().at("offline").value<bool>();
bool& offline = config.at("offline").value<bool>();
if (offline)
{
LOG_DEBUG << "SSL verification disabled by offline mode";
@ -398,7 +404,7 @@ namespace mamba
return;
}
auto& cacert = Configuration::instance().at("cacert_path").value<std::string>();
auto& cacert = config.at("cacert_path").value<std::string>();
if (!cacert.empty())
{
value = cacert;
@ -413,9 +419,8 @@ namespace mamba
}
};
void always_softlink_hook(bool& value)
void always_softlink_hook(Configuration& config, bool& value)
{
auto& config = Configuration::instance();
auto& always_copy = config.at("always_copy").value<bool>();
if (value && always_copy)
@ -489,11 +494,10 @@ namespace mamba
}
}
void env_name_hook(std::string& name)
void env_name_hook(Configuration& config, std::string& name)
{
file_spec_env_name_hook(name);
auto& config = Configuration::instance();
auto& root_prefix = config.at("root_prefix").value<fs::u8path>();
auto& env_name = config.at("env_name");
@ -534,9 +538,8 @@ namespace mamba
}
}
void target_prefix_hook(fs::u8path& prefix)
void target_prefix_hook(Configuration& config, fs::u8path& prefix)
{
auto& config = Configuration::instance();
auto& root_prefix = config.at("root_prefix").value<fs::u8path>();
if (!prefix.empty())
@ -575,15 +578,15 @@ namespace mamba
prefix = rstrip(fs::weakly_canonical(env::expand_user(prefix)).string(), sep);
}
if ((prefix == root_prefix) && Configuration::instance().at("create_base").value<bool>())
if ((prefix == root_prefix) && config.at("create_base").value<bool>())
{
path::touch(root_prefix / "conda-meta" / "history", true);
}
}
void root_prefix_hook(fs::u8path& prefix)
void root_prefix_hook(Configuration& config, fs::u8path& prefix)
{
auto& env_name = Configuration::instance().at("env_name");
auto& env_name = config.at("env_name");
if (prefix.empty())
{
@ -644,34 +647,31 @@ namespace mamba
prefix = fs::weakly_canonical(env::expand_user(prefix));
}
void rc_loading_hook(const RCConfigLevel& level)
void rc_loading_hook(Configuration& config, const RCConfigLevel& level)
{
auto& config = Configuration::instance();
auto& rc_files = config.at("rc_files").value<std::vector<fs::u8path>>();
config.set_rc_values(rc_files, level);
}
void post_root_prefix_rc_loading()
void post_root_prefix_rc_loading(Configuration& config)
{
auto& config = Configuration::instance();
if (!Context::instance().src_params.no_rc)
{
rc_loading_hook(RCConfigLevel::kHomeDir);
rc_loading_hook(config, RCConfigLevel::kHomeDir);
config.at("no_env").compute(MAMBA_CONF_FORCE_COMPUTE);
}
}
void post_target_prefix_rc_loading()
void post_target_prefix_rc_loading(Configuration& config)
{
auto& config = Configuration::instance();
if (!Context::instance().src_params.no_rc)
{
rc_loading_hook(RCConfigLevel::kTargetPrefix);
rc_loading_hook(config, RCConfigLevel::kTargetPrefix);
config.at("no_env").compute(MAMBA_CONF_FORCE_COMPUTE);
}
}
mamba::log_level log_level_fallback_hook()
mamba::log_level log_level_fallback_hook(Configuration& config)
{
auto& ctx = Context::instance();
@ -679,7 +679,7 @@ namespace mamba
{
return mamba::log_level::critical;
}
else if (Configuration::instance().at("verbose").configured())
else if (config.at("verbose").configured())
{
switch (ctx.output_params.verbosity)
{
@ -796,31 +796,31 @@ namespace mamba
}
}
void print_config_only_hook(bool& value)
void print_config_only_hook(Configuration& config, bool& value)
{
if (value)
{
if (!Configuration::instance().at("debug").value<bool>())
if (!config.at("debug").value<bool>())
{
LOG_ERROR << "Debug mode required to use 'print_config_only'";
throw std::runtime_error("Aborting.");
}
Configuration::instance().at("quiet").set_value(true);
Configuration::instance().at("json").set_value(false);
config.at("quiet").set_value(true);
config.at("json").set_value(false);
}
}
void print_context_only_hook(bool& value)
void print_context_only_hook(Configuration& config, bool& value)
{
if (value)
{
if (!Configuration::instance().at("debug").value<bool>())
if (!config.at("debug").value<bool>())
{
LOG_ERROR << "Debug mode required to use 'print_context_only'";
throw std::runtime_error("Aborting.");
}
Configuration::instance().at("quiet").set_value(true);
Configuration::instance().at("json").set_value(false);
config.at("quiet").set_value(true);
config.at("json").set_value(false);
}
}
@ -909,9 +909,9 @@ namespace mamba
}
}
void use_conda_root_prefix(bool force)
void use_conda_root_prefix(Configuration& config, bool force)
{
if (!Configuration::instance().at("root_prefix").configured() || force)
if (!config.at("root_prefix").configured() || force)
{
env::set("MAMBA_ROOT_PREFIX", get_conda_root_prefix().string());
}
@ -1055,13 +1055,16 @@ namespace mamba
auto& ctx = Context::instance();
// Basic
insert(Configurable("root_prefix", &ctx.prefix_params.root_prefix)
.group("Basic")
.set_env_var_names()
.needs({ "create_base", "rc_files" })
.description("Path to the root prefix")
.set_post_merge_hook(detail::root_prefix_hook)
.set_post_context_hook(detail::post_root_prefix_rc_loading));
insert(
Configurable("root_prefix", &ctx.prefix_params.root_prefix)
.group("Basic")
.set_env_var_names()
.needs({ "create_base", "rc_files" })
.description("Path to the root prefix")
.set_post_merge_hook<fs::u8path>([&](fs::u8path& value)
{ return detail::root_prefix_hook(*this, value); })
.set_post_context_hook([this] { return detail::post_root_prefix_rc_loading(*this); })
);
insert(Configurable("create_base", false)
.group("Basic")
@ -1078,8 +1081,11 @@ namespace mamba
"use_target_prefix_fallback" })
.set_single_op_lifetime()
.description("Path to the target prefix")
.set_post_merge_hook(detail::target_prefix_hook)
.set_post_context_hook(detail::post_target_prefix_rc_loading));
.set_post_merge_hook<fs::u8path>(
[this](fs::u8path& value) { return detail::target_prefix_hook(*this, value); }
)
.set_post_context_hook([this]
{ return detail::post_target_prefix_rc_loading(*this); }));
insert(Configurable("relocate_prefix", &ctx.prefix_params.relocate_prefix)
.group("Basic")
@ -1104,7 +1110,8 @@ namespace mamba
.group("Basic")
.needs({ "root_prefix", "spec_file_env_name", "envs_dirs" })
.set_single_op_lifetime()
.set_post_merge_hook(detail::env_name_hook)
.set_post_merge_hook<std::string>([&](std::string& value)
{ return detail::env_name_hook(*this, value); })
.description("Name of the target prefix"));
insert(Configurable("envs_dirs", &ctx.envs_dirs)
@ -1184,7 +1191,10 @@ namespace mamba
.long_description(unindent(R"(
The list of channels where the packages will be searched for.
See also 'channel_priority'.)"))
.set_post_merge_hook(detail::channels_hook));
.set_post_merge_hook<decltype(ctx.channels)>(
[&](decltype(ctx.channels)& value)
{ return detail::channels_hook(*this, value); }
));
insert(Configurable("channel_alias", &ctx.channel_alias)
.group("Channels")
@ -1282,7 +1292,9 @@ namespace mamba
the string "<false>" to indicate no SSL verification, or a path to
a directory with cert files, or a cert file..)"))
.needs({ "cacert_path", "offline" })
.set_post_merge_hook(detail::ssl_verify_hook));
.set_post_merge_hook<decltype(ctx.remote_fetch_params.ssl_verify)>(
[this](auto&... args) { return detail::ssl_verify_hook(*this, args...); }
));
insert(Configurable("proxy_servers", &ctx.proxy_servers)
.group("Network")
@ -1338,7 +1350,10 @@ namespace mamba
insert(Configurable("file_specs", std::vector<std::string>({}))
.group("Solver")
.set_post_merge_hook(detail::file_specs_hook)
.set_post_merge_hook<std::vector<std::string>>(
[&](std::vector<std::string>& value)
{ return detail::file_specs_hook(*this, value); }
)
.description("File (yaml, explicit or plain)"));
insert(Configurable("no_pin", false)
@ -1455,7 +1470,10 @@ namespace mamba
.set_rc_configurable()
.set_env_var_names()
.needs({ "always_copy" })
.set_post_merge_hook(detail::always_softlink_hook)
.set_post_merge_hook<decltype(ctx.always_softlink)>(
[&](decltype(ctx.always_softlink)& value)
{ return detail::always_softlink_hook(*this, value); }
)
.description("Use soft-link instead of hard-link")
.long_description(unindent(R"(
Register a preference that files be soft-linked (symlinked) into a
@ -1558,7 +1576,9 @@ namespace mamba
.set_env_var_names()
.needs({ "json", "verbose" })
.description("Set the log level")
.set_fallback_value_hook(detail::log_level_fallback_hook)
.set_fallback_value_hook<mamba::log_level>(
[this] { return detail::log_level_fallback_hook(*this); }
)
.long_description(unindent(R"(
Set globally the log level of all loggers. Log level can
be one of {'off', 'fatal', 'error', 'warning', 'info',
@ -1619,13 +1639,17 @@ namespace mamba
insert(Configurable("print_config_only", false)
.group("Output, Prompt and Flow Control")
.needs({ "debug" })
.set_post_merge_hook(detail::print_config_only_hook)
.set_post_merge_hook<bool>(
[&](bool& value) { return detail::print_config_only_hook(*this, value); }
)
.description("Print the context after loading the config. Allow ultra-dry runs"));
insert(Configurable("print_context_only", false)
.group("Output, Prompt and Flow Control")
.needs({ "debug" })
.set_post_merge_hook(detail::print_context_only_hook)
.set_post_merge_hook<bool>(
[&](bool& value) { return detail::print_context_only_hook(*this, value); }
)
.description("Print the context after loading the config. Allow ultra-dry runs"));
insert(Configurable("show_banner", true)
@ -1715,10 +1739,10 @@ namespace mamba
set_configurables();
}
auto Configuration::get_grouped_config() -> std::vector<grouped_config_type>
auto Configuration::get_grouped_config() const -> std::vector<grouped_config_type>
{
std::map<std::string, std::vector<Configurable*>> map;
std::vector<std::pair<std::string, std::vector<Configurable*>>> res;
std::map<std::string, std::vector<const Configurable*>> map;
std::vector<std::pair<std::string, std::vector<const Configurable*>>> res;
std::vector<std::string> group_order;
for (auto& name : m_config_order)
@ -1827,7 +1851,13 @@ namespace mamba
LOG_DEBUG << m_config.size() << " configurables computed";
CONFIG_DEBUGGING;
if (this->at("print_config_only").value<bool>())
{
int dump_opts = MAMBA_SHOW_CONFIG_VALUES | MAMBA_SHOW_CONFIG_SRCS
| MAMBA_SHOW_ALL_CONFIGS;
std::cout << this->dump(dump_opts) << std::endl;
exit(0);
}
if (at("show_banner").value<bool>())
{
@ -1961,12 +1991,12 @@ namespace mamba
}
}
std::vector<fs::u8path> Configuration::sources()
std::vector<fs::u8path> Configuration::sources() const
{
return m_sources;
}
std::vector<fs::u8path> Configuration::valid_sources()
std::vector<fs::u8path> Configuration::valid_sources() const
{
return m_valid_sources;
}
@ -1976,17 +2006,36 @@ namespace mamba
return m_config;
}
const std::map<std::string, Configurable>& Configuration::config() const
{
return m_config;
}
namespace
{
template <typename MapType>
auto& configuration_at_impl(const std::string& key, MapType&& map)
{
try
{
return std::forward<MapType>(map).at(key);
}
catch (const std::out_of_range& /*e*/)
{
LOG_ERROR << "Configurable '" << key << "' does not exists";
throw std::runtime_error("ConfigurationError");
}
}
}
Configurable& Configuration::at(const std::string& name)
{
try
{
return m_config.at(name);
}
catch (const std::out_of_range& /*e*/)
{
LOG_ERROR << "Configurable '" << name << "' does not exists";
throw std::runtime_error("ConfigurationError");
}
return configuration_at_impl(name, m_config);
}
const Configurable& Configuration::at(const std::string& name) const
{
return configuration_at_impl(name, m_config);
}
YAML::Node Configuration::load_rc_file(const fs::u8path& file)
@ -2276,7 +2325,7 @@ namespace mamba
return out.c_str();
}
std::string Configuration::dump(int opts, std::vector<std::string> names)
std::string Configuration::dump(int opts, std::vector<std::string> names) const
{
if (m_config.at("json").value<bool>())
{

View File

@ -14,10 +14,9 @@
namespace mamba
{
void create()
void create(Configuration& config)
{
auto& ctx = Context::instance();
auto& config = Configuration::instance();
config.at("use_target_prefix_fallback").set_value(false);
config.at("target_prefix_checks")
@ -79,7 +78,7 @@ namespace mamba
install_lockfile_specs(
channel_context,
lockfile_path,
Configuration::instance().at("categories").value<std::vector<std::string>>(),
config.at("categories").value<std::vector<std::string>>(),
true
);
}
@ -91,11 +90,9 @@ namespace mamba
}
else
{
install_specs(channel_context, create_specs, true);
install_specs(channel_context, config, create_specs, true);
}
}
config.operation_teardown();
}
namespace detail

View File

@ -21,10 +21,8 @@ extern "C"
namespace mamba
{
void info()
void info(Configuration& config)
{
auto& config = Configuration::instance();
config.at("use_target_prefix_fallback").set_value(true);
config.at("target_prefix_checks")
.set_value(
@ -33,7 +31,7 @@ namespace mamba
config.load();
ChannelContext channel_context;
detail::print_info(channel_context);
detail::print_info(channel_context, config);
config.operation_teardown();
}
@ -93,7 +91,7 @@ namespace mamba
Console::instance().json_write(items_map);
}
void print_info(ChannelContext& channel_context)
void print_info(ChannelContext& channel_context, const Configuration& config)
{
auto& ctx = Context::instance();
std::vector<std::tuple<std::string, nlohmann::json>> items;
@ -135,7 +133,6 @@ namespace mamba
items.push_back({ "user config files",
{ (env::home_directory() / ".mambarc").string() } });
Configuration& config = Configuration::instance();
std::vector<std::string> sources;
for (auto s : config.valid_sources())
{

View File

@ -376,10 +376,8 @@ namespace mamba
}
}
void install()
void install(Configuration& config)
{
auto& config = Configuration::instance();
config.at("create_base").set_value(true);
config.at("use_target_prefix_fallback").set_value(true);
config.at("target_prefix_checks")
@ -401,7 +399,7 @@ namespace mamba
install_lockfile_specs(
channel_context,
lockfile_path,
Configuration::instance().at("categories").value<std::vector<std::string>>(),
config.at("categories").value<std::vector<std::string>>(),
false
);
}
@ -413,15 +411,13 @@ namespace mamba
}
else
{
mamba::install_specs(channel_context, install_specs, false);
mamba::install_specs(channel_context, config, install_specs, false);
}
}
else
{
Console::instance().print("Nothing to do.");
}
config.operation_teardown();
}
int RETRY_SUBDIR_FETCH = 1 << 0;
@ -429,6 +425,7 @@ namespace mamba
void install_specs(
ChannelContext& channel_context,
const Configuration& config,
const std::vector<std::string>& specs,
bool create_env,
int solver_flag,
@ -436,7 +433,6 @@ namespace mamba
)
{
auto& ctx = Context::instance();
auto& config = Configuration::instance();
auto& no_pin = config.at("no_pin").value<bool>();
auto& no_py_pin = config.at("no_py_pin").value<bool>();
@ -564,6 +560,7 @@ namespace mamba
ctx.local_repodata_ttl = 2;
return install_specs(
channel_context,
config,
specs,
create_env,
solver_flag,
@ -739,9 +736,8 @@ namespace mamba
env_manager.register_env(prefix);
}
void file_specs_hook(std::vector<std::string>& file_specs)
void file_specs_hook(Configuration& config, std::vector<std::string>& file_specs)
{
auto& config = Configuration::instance();
auto& env_name = config.at("spec_file_env_name");
auto& specs = config.at("specs");
auto& others_pkg_mgrs_specs = config.at("others_pkg_mgrs_specs");
@ -890,9 +886,8 @@ namespace mamba
}
}
void channels_hook(std::vector<std::string>& channels)
void channels_hook(Configuration& config, std::vector<std::string>& channels)
{
auto& config = Configuration::instance();
auto& config_channels = config.at("channels");
std::vector<std::string> cli_channels;

View File

@ -15,10 +15,8 @@
namespace mamba
{
void list(const std::string& regex)
void list(Configuration& config, const std::string& regex)
{
auto& config = Configuration::instance();
config.at("show_banner").set_value(false);
config.at("use_target_prefix_fallback").set_value(true);
config.at("target_prefix_checks")
@ -30,8 +28,6 @@ namespace mamba
ChannelContext channel_context;
detail::list_packages(regex, channel_context);
config.operation_teardown();
}
namespace detail

View File

@ -17,14 +17,13 @@
namespace mamba
{
void remove(int flags)
void remove(Configuration& config, int flags)
{
bool prune = flags & MAMBA_REMOVE_PRUNE;
bool force = flags & MAMBA_REMOVE_FORCE;
bool remove_all = flags & MAMBA_REMOVE_ALL;
auto& ctx = Context::instance();
auto& config = Configuration::instance();
config.at("use_target_prefix_fallback").set_value(true);
config.at("target_prefix_checks")
@ -61,8 +60,6 @@ namespace mamba
{
Console::instance().print("Nothing to do.");
}
config.operation_teardown();
}
namespace detail

View File

@ -17,10 +17,15 @@
namespace mamba
{
void repoquery(QueryType type, QueryResultFormat format, bool use_local, const std::string& query)
void repoquery(
Configuration& config,
QueryType type,
QueryResultFormat format,
bool use_local,
const std::string& query
)
{
auto& ctx = Context::instance();
auto& config = Configuration::instance();
config.at("show_banner").set_value(false);
config.at("use_target_prefix_fallback").set_value(true);
@ -150,7 +155,5 @@ namespace mamba
<< std::endl;
}
}
config.operation_teardown();
}
}

View File

@ -16,10 +16,9 @@
namespace mamba
{
void update(bool update_all, bool prune)
void update(Configuration& config, bool update_all, bool prune)
{
auto& ctx = Context::instance();
auto& config = Configuration::instance();
config.at("use_target_prefix_fallback").set_value(true);
config.at("target_prefix_checks")
@ -150,7 +149,5 @@ namespace mamba
MTransaction transaction(pool, solver, package_caches);
execute_transaction(transaction);
config.operation_teardown();
}
}

View File

@ -179,13 +179,6 @@ namespace mamba
static std::unique_ptr<Singleton<Context>> context;
static std::unique_ptr<Singleton<Console>> console;
static std::unique_ptr<Singleton<Configuration>> config;
}
Configuration& Configuration::instance()
{
return singletons::init_once(singletons::config);
}
Context& Context::instance()

View File

@ -37,7 +37,7 @@ namespace mamba
m_channel_alias_bu = ctx.channel_alias;
m_ssl_verify = ctx.remote_fetch_params.ssl_verify;
m_proxy_servers = ctx.proxy_servers;
mamba::Configuration::instance().at("show_banner").set_default_value(false);
config.at("show_banner").set_default_value(false);
}
~Configuration()
@ -60,12 +60,10 @@ namespace mamba
out_file << rc;
out_file.close();
mamba::Configuration::instance().reset_configurables();
mamba::Configuration::instance()
.at("rc_files")
.set_value<std::vector<fs::u8path>>({ unique_location });
mamba::Configuration::instance().at("show_banner").set_default_value(false);
mamba::Configuration::instance().load();
config.reset_configurables();
config.at("rc_files").set_value<std::vector<fs::u8path>>({ unique_location });
config.at("show_banner").set_default_value(false);
config.load();
}
void load_test_config(std::vector<std::string> rcs)
@ -85,10 +83,10 @@ namespace mamba
sources.push_back(loc);
}
mamba::Configuration::instance().reset_configurables();
mamba::Configuration::instance().at("rc_files").set_value(sources);
mamba::Configuration::instance().at("show_banner").set_default_value(false);
mamba::Configuration::instance().load();
config.reset_configurables();
config.at("rc_files").set_value(sources);
config.at("show_banner").set_default_value(false);
config.load();
}
std::string shrink_source(std::size_t position)
@ -100,9 +98,10 @@ namespace mamba
".yaml"
);
mamba::Configuration& config = mamba::Configuration::instance();
mamba::Context& ctx = mamba::Context::instance();
mamba::Configuration config;
private:
// Variables to restore the original COntext state and avoid

View File

@ -117,6 +117,7 @@ namespace mambapy
struct Singletons
{
mamba::ChannelContext channel_context;
mamba::Configuration config;
};
Singletons& singletons()
@ -960,16 +961,18 @@ PYBIND11_MODULE(bindings, m)
}
);
m.def("clean", &clean);
m.def("clean", [](int flags) { return clean(mambapy::singletons().config, flags); });
py::class_<Configuration, std::unique_ptr<Configuration, py::nodelete>>(m, "Configuration")
.def(py::init(
[]() { return std::unique_ptr<Configuration, py::nodelete>(&Configuration::instance()); }
[]()
{ return std::unique_ptr<Configuration, py::nodelete>(&mambapy::singletons().config); }
))
.def_property(
"show_banner",
[]() -> bool { return Configuration::instance().at("show_banner").value<bool>(); },
[](py::object&, bool val) { Configuration::instance().at("show_banner").set_value(val); }
[]() -> bool { return mambapy::singletons().config.at("show_banner").value<bool>(); },
[](py::object&, bool val)
{ mambapy::singletons().config.at("show_banner").set_value(val); }
);
m.def(

View File

@ -20,6 +20,7 @@ main(int argc, char** argv)
{
using namespace mamba; // NOLINT(build/namespaces)
Configuration config;
CLI::App app{ "Version: " + version() + "\n" };
set_package_command(&app);
@ -34,9 +35,10 @@ main(int argc, char** argv)
return 1;
}
if (app.get_subcommands().size() == 0)
{
Configuration::instance().load();
config.load();
Console::instance().print(app.help());
}

View File

@ -13,11 +13,9 @@
using namespace mamba; // NOLINT(build/namespaces)
void
init_clean_parser(CLI::App* subcom)
init_clean_parser(CLI::App* subcom, Configuration& config)
{
init_general_options(subcom);
auto& config = Configuration::instance();
init_general_options(subcom, config);
auto& clean_all = config.insert(
Configurable("clean_all", false)
@ -70,14 +68,13 @@ init_clean_parser(CLI::App* subcom)
}
void
set_clean_command(CLI::App* subcom)
set_clean_command(CLI::App* subcom, Configuration& config)
{
init_clean_parser(subcom);
init_clean_parser(subcom, config);
subcom->callback(
[&]()
{
auto& config = Configuration::instance();
int options = 0;
if (config.at("clean_all").compute().value<bool>())
@ -113,7 +110,7 @@ set_clean_command(CLI::App* subcom)
}
}
clean(options);
clean(config, options);
}
);
}

View File

@ -11,9 +11,8 @@
using namespace mamba; // NOLINT(build/namespaces)
void
init_rc_options(CLI::App* subcom)
init_rc_options(CLI::App* subcom, Configuration& config)
{
auto& config = Configuration::instance();
std::string cli_group = "Configuration options";
auto& rc_files = config.at("rc_files");
@ -34,11 +33,10 @@ init_rc_options(CLI::App* subcom)
void
init_general_options(CLI::App* subcom)
init_general_options(CLI::App* subcom, Configuration& config)
{
init_rc_options(subcom);
init_rc_options(subcom, config);
auto& config = Configuration::instance();
std::string cli_group = "Global options";
auto& verbose = config.at("verbose");
@ -105,9 +103,8 @@ init_general_options(CLI::App* subcom)
}
void
init_prefix_options(CLI::App* subcom)
init_prefix_options(CLI::App* subcom, Configuration& config)
{
auto& config = Configuration::instance();
std::string cli_group = "Prefix options";
auto& root = config.at("root_prefix");
@ -134,9 +131,8 @@ init_prefix_options(CLI::App* subcom)
void
init_network_options(CLI::App* subcom)
init_network_options(CLI::App* subcom, Configuration& config)
{
auto& config = Configuration::instance();
std::string cli_group = "Network options";
auto& ssl_verify = config.at("ssl_verify");
@ -179,10 +175,9 @@ init_network_options(CLI::App* subcom)
void
init_channel_parser(CLI::App* subcom)
init_channel_parser(CLI::App* subcom, Configuration& config)
{
using string_list = std::vector<std::string>;
auto& config = Configuration::instance();
auto& channels = config.at("channels");
channels.needs({ "override_channels" });
@ -197,7 +192,8 @@ init_channel_parser(CLI::App* subcom)
.set_env_var_names()
.description("Override channels")
.needs({ "override_channels_enabled" })
.set_post_merge_hook(override_channels_hook),
.set_post_merge_hook<bool>([&](bool& value)
{ return override_channels_hook(config, value); }),
true
);
subcom->add_flag(
@ -229,7 +225,8 @@ init_channel_parser(CLI::App* subcom)
Configurable("strict_channel_priority", false)
.group("cli")
.description("Enable strict channel priority")
.set_post_merge_hook(strict_channel_priority_hook),
.set_post_merge_hook<bool>([&](bool& value)
{ return strict_channel_priority_hook(config, value); }),
true
);
subcom->add_flag(
@ -242,7 +239,8 @@ init_channel_parser(CLI::App* subcom)
Configurable("no_channel_priority", false)
.group("cli")
.description("Disable channel priority")
.set_post_merge_hook(no_channel_priority_hook),
.set_post_merge_hook<bool>([&](bool& value)
{ return no_channel_priority_hook(config, value); }),
true
);
subcom->add_flag(
@ -255,9 +253,8 @@ init_channel_parser(CLI::App* subcom)
}
void
override_channels_hook(bool& value)
override_channels_hook(Configuration& config, bool& value)
{
auto& config = Configuration::instance();
auto& override_channels = config.at("override_channels");
auto& channels = config.at("channels");
bool override_channels_enabled = config.at("override_channels_enabled").value<bool>();
@ -282,9 +279,8 @@ override_channels_hook(bool& value)
}
void
strict_channel_priority_hook(bool&)
strict_channel_priority_hook(Configuration& config, bool&)
{
auto& config = Configuration::instance();
auto& channel_priority = config.at("channel_priority");
auto& strict_channel_priority = config.at("strict_channel_priority");
auto& no_channel_priority = config.at("no_channel_priority");
@ -312,9 +308,8 @@ strict_channel_priority_hook(bool&)
}
void
no_channel_priority_hook(bool&)
no_channel_priority_hook(Configuration& config, bool&)
{
auto& config = Configuration::instance();
auto& channel_priority = config.at("channel_priority");
auto& no_channel_priority = config.at("no_channel_priority");
auto& strict_channel_priority = config.at("strict_channel_priority");
@ -341,15 +336,13 @@ no_channel_priority_hook(bool&)
}
void
init_install_options(CLI::App* subcom)
init_install_options(CLI::App* subcom, Configuration& config)
{
using string_list = std::vector<std::string>;
init_general_options(subcom);
init_prefix_options(subcom);
init_network_options(subcom);
init_channel_parser(subcom);
auto& config = Configuration::instance();
init_general_options(subcom, config);
init_prefix_options(subcom, config);
init_network_options(subcom, config);
init_channel_parser(subcom, config);
auto& specs = config.at("specs");
subcom->add_option(

View File

@ -9,32 +9,33 @@
#include <CLI/CLI.hpp>
#include "mamba/api/configuration.hpp"
#include "mamba/core/context.hpp"
void
init_rc_options(CLI::App* subcom);
init_rc_options(CLI::App* subcom, mamba::Configuration& config);
void
init_general_options(CLI::App* subcom);
init_general_options(CLI::App* subcom, mamba::Configuration& config);
void
init_prefix_options(CLI::App* subcom);
init_prefix_options(CLI::App* subcom, mamba::Configuration& config);
void
init_install_options(CLI::App* subcom);
init_install_options(CLI::App* subcom, mamba::Configuration& config);
void
init_network_options(CLI::App* subcom);
init_network_options(CLI::App* subcom, mamba::Configuration& config);
void
strict_channel_priority_hook(bool& value);
strict_channel_priority_hook(mamba::Configuration& config, bool& value);
void
no_channel_priority_hook(bool& value);
no_channel_priority_hook(mamba::Configuration& config, bool& value);
void
init_channel_parser(CLI::App* subcom);
init_channel_parser(CLI::App* subcom, mamba::Configuration& config);
void
load_channel_options(mamba::Context& ctx);
@ -43,6 +44,6 @@ void
channels_hook(std::vector<std::string>& channels);
void
override_channels_hook(bool& override_channels);
override_channels_hook(mamba::Configuration& config, bool& override_channels);
#endif

View File

@ -16,7 +16,12 @@
void
complete_options(CLI::App* app, const std::vector<std::string>& last_args, bool& completed)
complete_options(
CLI::App* app,
mamba::Configuration& config,
const std::vector<std::string>& last_args,
bool& completed
)
{
if (completed || last_args.empty())
{
@ -28,7 +33,6 @@ complete_options(CLI::App* app, const std::vector<std::string>& last_args, bool&
if (last_args[0] == "-n" && last_args.size() == 2)
{
auto& config = mamba::Configuration::instance();
config.at("show_banner").set_value(false);
config.load();
@ -103,22 +107,28 @@ complete_options(CLI::App* app, const std::vector<std::string>& last_args, bool&
void
overwrite_callbacks(
std::vector<CLI::App*>& apps,
mamba::Configuration& config,
const std::vector<std::string>& completer_args,
bool& completed
)
{
auto* app = apps.back();
app->callback([app, &completer_args, &completed]()
{ complete_options(app, completer_args, completed); });
app->callback([app, &completer_args, &completed, &config]()
{ complete_options(app, config, completer_args, completed); });
for (auto* subc : app->get_subcommands(nullptr))
{
apps.push_back(subc);
overwrite_callbacks(apps, completer_args, completed);
overwrite_callbacks(apps, config, completer_args, completed);
}
}
void
add_activate_completion(CLI::App* app, std::vector<std::string>& completer_args, bool& completed)
add_activate_completion(
CLI::App* app,
mamba::Configuration& config,
std::vector<std::string>& completer_args,
bool& completed
)
{
auto* current_subcom = app->get_subcommand("activate");
app->remove_subcommand(current_subcom);
@ -127,19 +137,24 @@ add_activate_completion(CLI::App* app, std::vector<std::string>& completer_args,
CLI::App* activate_subcom = app->add_subcommand("activate");
app->add_subcommand("deactivate");
activate_subcom->callback(
[app, &completer_args, &completed]()
[app, &completer_args, &completed, &config]()
{
if (completer_args.size() == 1)
{
completer_args = { "-n", completer_args.back() };
complete_options(app, completer_args, completed);
complete_options(app, config, completer_args, completed);
}
}
);
}
void
add_ps_completion(CLI::App* app, std::vector<std::string>& completer_args, bool& completed)
add_ps_completion(
CLI::App* app,
mamba::Configuration& config,
std::vector<std::string>& completer_args,
bool& completed
)
{
auto* current_subcom = app->get_subcommand("ps");
app->remove_subcommand(current_subcom);
@ -151,11 +166,11 @@ add_ps_completion(CLI::App* app, std::vector<std::string>& completer_args, bool&
CLI::App* list_subcom = ps_subcom->add_subcommand("list");
ps_subcom->callback([ps_subcom, &completer_args, &completed]()
{ complete_options(ps_subcom, completer_args, completed); });
ps_subcom->callback([ps_subcom, &completer_args, &completed, &config]()
{ complete_options(ps_subcom, config, completer_args, completed); });
list_subcom->callback([list_subcom, &completer_args, &completed]()
{ complete_options(list_subcom, completer_args, completed); });
list_subcom->callback([list_subcom, &completer_args, &completed, &config]()
{ complete_options(list_subcom, config, completer_args, completed); });
stop_subcom->callback(
[&completer_args, &completed]()
@ -182,7 +197,7 @@ add_ps_completion(CLI::App* app, std::vector<std::string>& completer_args, bool&
void
get_completions(CLI::App* app, int argc, char** argv)
get_completions(CLI::App* app, mamba::Configuration& config, int argc, char** argv)
{
std::vector<std::string> completer_args;
bool completed = false;
@ -199,9 +214,9 @@ get_completions(CLI::App* app, int argc, char** argv)
}
std::vector<CLI::App*> apps = { app };
overwrite_callbacks(apps, completer_args, completed);
add_activate_completion(app, completer_args, completed);
add_ps_completion(app, completer_args, completed);
overwrite_callbacks(apps, config, completer_args, completed);
add_activate_completion(app, config, completer_args, completed);
add_ps_completion(app, config, completer_args, completed);
argv[1] = argv[0];
try

View File

@ -18,9 +18,8 @@
using namespace mamba; // NOLINT(build/namespaces)
bool
is_valid_rc_key(const std::string& key)
is_valid_rc_key(const mamba::Configuration& config, const std::string& key)
{
auto& config = Configuration::instance();
try
{
return config.config().at(key).rc_configurable();
@ -32,12 +31,11 @@ is_valid_rc_key(const std::string& key)
}
bool
is_valid_rc_sequence(const std::string& key, const std::string& value)
is_valid_rc_sequence(const mamba::Configuration& config, const std::string& key, const std::string& value)
{
auto& config = Configuration::instance();
try
{
auto& c = config.config().at(key);
const auto& c = config.config().at(key);
return c.is_valid_serialization(value) && c.rc_configurable() && c.is_sequence();
}
catch (const std::out_of_range& /*e*/)
@ -54,9 +52,8 @@ get_system_path()
}
fs::u8path
compute_config_path(bool touch_if_not_exists)
compute_config_path(Configuration& config, bool touch_if_not_exists)
{
auto& config = Configuration::instance();
auto& ctx = Context::instance();
auto& file_path = config.at("config_set_file_path");
@ -94,17 +91,15 @@ compute_config_path(bool touch_if_not_exists)
}
void
init_config_options(CLI::App* subcom)
init_config_options(CLI::App* subcom, mamba::Configuration& config)
{
init_general_options(subcom);
init_prefix_options(subcom);
init_general_options(subcom, config);
init_prefix_options(subcom, config);
}
void
init_config_describe_options(CLI::App* subcom)
init_config_describe_options(CLI::App* subcom, mamba::Configuration& config)
{
auto& config = Configuration::instance();
auto& specs = config.at("specs");
subcom->add_option("configs", specs.get_cli_config<std::vector<std::string>>(), "Configuration keys");
@ -120,12 +115,10 @@ init_config_describe_options(CLI::App* subcom)
}
void
init_config_list_options(CLI::App* subcom)
init_config_list_options(CLI::App* subcom, mamba::Configuration& config)
{
init_config_options(subcom);
init_config_describe_options(subcom);
auto& config = Configuration::instance();
init_config_options(subcom, config);
init_config_describe_options(subcom, config);
auto& show_sources = config.at("show_config_sources");
subcom->add_flag("-s,--sources", show_sources.get_cli_config<bool>(), show_sources.description());
@ -142,52 +135,50 @@ init_config_list_options(CLI::App* subcom)
}
void
set_config_list_command(CLI::App* subcom)
set_config_list_command(CLI::App* subcom, mamba::Configuration& config)
{
init_config_list_options(subcom);
init_config_list_options(subcom, config);
subcom->callback(
[&]()
{
config_list();
config_list(config);
return 0;
}
);
}
void
set_config_sources_command(CLI::App* subcom)
set_config_sources_command(CLI::App* subcom, mamba::Configuration& config)
{
init_config_options(subcom);
init_config_options(subcom, config);
subcom->callback(
[&]()
{
config_sources();
config_sources(config);
return 0;
}
);
}
void
set_config_describe_command(CLI::App* subcom)
set_config_describe_command(CLI::App* subcom, mamba::Configuration& config)
{
init_config_describe_options(subcom);
init_config_describe_options(subcom, config);
subcom->callback(
[&]()
[&]
{
config_describe();
config_describe(config);
return 0;
}
);
}
void
set_config_path_command(CLI::App* subcom)
set_config_path_command(CLI::App* subcom, mamba::Configuration& config)
{
auto& config = Configuration::instance();
auto& system_path = config.insert(
Configurable("config_set_system_path", false)
.group("cli")
@ -229,12 +220,11 @@ enum class SequenceAddType
};
void
set_config_sequence_command(CLI::App* subcom)
set_config_sequence_command(CLI::App* subcom, mamba::Configuration& config)
{
set_config_path_command(subcom);
set_config_path_command(subcom, config);
using config_set_sequence_type = std::vector<std::pair<std::string, std::string>>;
auto& config = Configuration::instance();
auto& specs = config.insert(
Configurable("config_set_sequence_spec", config_set_sequence_type({}))
.group("Output, Prompt and Flow Control")
@ -248,15 +238,16 @@ set_config_sequence_command(CLI::App* subcom)
void
set_sequence_to_yaml(
mamba::Configuration& config,
YAML::Node& node,
const std::string& key,
const std::string& value,
const SequenceAddType& opt
)
{
if (!is_valid_rc_sequence(key, value))
if (!is_valid_rc_sequence(config, key, value))
{
if (!is_valid_rc_key(key))
if (!is_valid_rc_key(config, key))
{
LOG_ERROR << "Invalid key '" << key << "' or not rc configurable";
}
@ -303,10 +294,8 @@ set_sequence_to_yaml(
}
void
set_sequence_to_rc(const SequenceAddType& opt)
set_sequence_to_rc(mamba::Configuration& config, const SequenceAddType& opt)
{
auto& config = Configuration::instance();
config.at("use_target_prefix_fallback").set_value(true);
config.at("show_banner").set_value(false);
config.at("target_prefix_checks")
@ -319,12 +308,12 @@ set_sequence_to_rc(const SequenceAddType& opt)
auto specs = config.at("config_set_sequence_spec")
.value<std::vector<std::pair<std::string, std::string>>>();
fs::u8path rc_source = compute_config_path(true);
fs::u8path rc_source = compute_config_path(config, true);
YAML::Node node = YAML::LoadFile(rc_source.string());
for (auto& pair : specs)
{
set_sequence_to_yaml(node, pair.first, pair.second, opt);
set_sequence_to_yaml(config, node, pair.first, pair.second, opt);
}
std::ofstream rc_file = open_ofstream(rc_source, std::ofstream::in | std::ofstream::trunc);
@ -334,27 +323,25 @@ set_sequence_to_rc(const SequenceAddType& opt)
}
void
set_config_prepend_command(CLI::App* subcom)
set_config_prepend_command(CLI::App* subcom, mamba::Configuration& config)
{
set_config_sequence_command(subcom);
set_config_sequence_command(subcom, config);
subcom->get_option("specs")->description("Add value at the beginning of a configurable sequence");
subcom->callback([&]() { set_sequence_to_rc(SequenceAddType::kPrepend); });
subcom->callback([&] { set_sequence_to_rc(config, SequenceAddType::kPrepend); });
}
void
set_config_append_command(CLI::App* subcom)
set_config_append_command(CLI::App* subcom, mamba::Configuration& config)
{
set_config_sequence_command(subcom);
set_config_sequence_command(subcom, config);
subcom->get_option("specs")->description("Add value at the end of a configurable sequence");
subcom->callback([&]() { set_sequence_to_rc(SequenceAddType::kAppend); });
subcom->callback([&] { set_sequence_to_rc(config, SequenceAddType::kAppend); });
}
void
set_config_remove_key_command(CLI::App* subcom)
set_config_remove_key_command(CLI::App* subcom, mamba::Configuration& config)
{
set_config_path_command(subcom);
auto& config = Configuration::instance();
set_config_path_command(subcom, config);
auto& remove_key = config.insert(Configurable("remove_key", std::string(""))
.group("Output, Prompt and Flow Control")
@ -373,7 +360,7 @@ set_config_remove_key_command(CLI::App* subcom)
);
config.load();
const fs::u8path rc_source = compute_config_path(false);
const fs::u8path rc_source = compute_config_path(config, false);
bool key_removed = false;
// convert rc file to YAML::Node
@ -406,13 +393,11 @@ set_config_remove_key_command(CLI::App* subcom)
}
void
set_config_remove_command(CLI::App* subcom)
set_config_remove_command(CLI::App* subcom, mamba::Configuration& config)
{
using string_list = std::vector<std::string>;
// have to check if a string is a vector
set_config_path_command(subcom);
auto& config = Configuration::instance();
set_config_path_command(subcom, config);
auto& remove_vec_map = config.insert(
Configurable("remove", std::vector<std::string>())
@ -428,7 +413,7 @@ set_config_remove_command(CLI::App* subcom)
);
subcom->callback(
[&]()
[&]
{
config.at("use_target_prefix_fallback").set_value(true);
config.at("show_banner").set_value(false);
@ -439,7 +424,7 @@ set_config_remove_command(CLI::App* subcom)
);
config.load();
const fs::u8path rc_source = compute_config_path(false);
const fs::u8path rc_source = compute_config_path(config, false);
bool key_removed = false;
const string_list& rvm = remove_vec_map.value<string_list>();
@ -494,12 +479,10 @@ set_config_remove_command(CLI::App* subcom)
}
void
set_config_set_command(CLI::App* subcom)
set_config_set_command(CLI::App* subcom, mamba::Configuration& config)
{
using string_list = std::vector<std::string>;
set_config_path_command(subcom);
auto& config = Configuration::instance();
set_config_path_command(subcom, config);
auto& set_value = config.insert(Configurable("set_value", std::vector<std::string>({}))
.group("Output, Prompt and Flow Control")
@ -508,7 +491,7 @@ set_config_set_command(CLI::App* subcom)
subcom->callback(
[&]()
[&]
{
config.at("use_target_prefix_fallback").set_value(true);
config.at("show_banner").set_value(false);
@ -519,12 +502,12 @@ set_config_set_command(CLI::App* subcom)
);
config.load();
const fs::u8path rc_source = compute_config_path(true);
const fs::u8path rc_source = compute_config_path(config, true);
YAML::Node rc_YAML = YAML::LoadFile(rc_source.string());
const string_list& sv = set_value.value<string_list>();
if (is_valid_rc_key(sv.at(0)) && sv.size() < 3)
if (is_valid_rc_key(config, sv.at(0)) && sv.size() < 3)
{
rc_YAML[sv.at(0)] = sv.at(1);
}
@ -543,11 +526,9 @@ set_config_set_command(CLI::App* subcom)
}
void
set_config_get_command(CLI::App* subcom)
set_config_get_command(CLI::App* subcom, mamba::Configuration& config)
{
set_config_path_command(subcom);
auto& config = Configuration::instance();
set_config_path_command(subcom, config);
// TODO: get_value should be a vector of strings
auto& get_value = config.insert(Configurable("get_value", std::string(""))
@ -556,7 +537,7 @@ set_config_get_command(CLI::App* subcom)
subcom->add_option("get_value", get_value.get_cli_config<std::string>(), get_value.description());
subcom->callback(
[&]()
[&]
{
config.at("use_target_prefix_fallback").set_value(true);
config.at("show_banner").set_value(false);
@ -567,7 +548,7 @@ set_config_get_command(CLI::App* subcom)
);
config.load();
fs::u8path rc_source = compute_config_path(false);
fs::u8path rc_source = compute_config_path(config, false);
bool value_found = false;
@ -596,46 +577,46 @@ set_config_get_command(CLI::App* subcom)
}
void
set_config_command(CLI::App* subcom)
set_config_command(CLI::App* subcom, mamba::Configuration& config)
{
init_config_options(subcom);
init_config_options(subcom, config);
auto list_subcom = subcom->add_subcommand("list", "List configuration values");
set_config_list_command(list_subcom);
set_config_list_command(list_subcom, config);
auto sources_subcom = subcom->add_subcommand("sources", "Show configuration sources");
set_config_sources_command(sources_subcom);
set_config_sources_command(sources_subcom, config);
auto describe_subcom = subcom->add_subcommand("describe", "Describe given configuration parameters");
set_config_describe_command(describe_subcom);
set_config_describe_command(describe_subcom, config);
auto prepend_subcom = subcom->add_subcommand(
"prepend",
"Add one configuration value to the beginning of a list key"
);
set_config_prepend_command(prepend_subcom);
set_config_prepend_command(prepend_subcom, config);
auto append_subcom = subcom->add_subcommand(
"append",
"Add one configuration value to the end of a list key"
);
set_config_append_command(append_subcom);
set_config_append_command(append_subcom, config);
auto remove_key_subcom = subcom->add_subcommand(
"remove-key",
"Remove a configuration key and its values"
);
set_config_remove_key_command(remove_key_subcom);
set_config_remove_key_command(remove_key_subcom, config);
auto remove_subcom = subcom->add_subcommand(
"remove",
"Remove a configuration value from a list key. This removes all instances of the value."
);
set_config_remove_command(remove_subcom);
set_config_remove_command(remove_subcom, config);
auto set_subcom = subcom->add_subcommand("set", "Set a configuration value");
set_config_set_command(set_subcom);
set_config_set_command(set_subcom, config);
auto get_subcom = subcom->add_subcommand("get", "Get a configuration value");
set_config_get_command(get_subcom);
set_config_get_command(get_subcom, config);
}

View File

@ -20,10 +20,8 @@
using namespace mamba; // NOLINT(build/namespaces)
void
init_constructor_parser(CLI::App* subcom)
init_constructor_parser(CLI::App* subcom, Configuration& config)
{
auto& config = Configuration::instance();
auto& prefix = config.insert(Configurable("constructor_prefix", fs::u8path(""))
.group("cli")
.description("Extract the conda pkgs in <prefix>/pkgs"));
@ -51,29 +49,27 @@ init_constructor_parser(CLI::App* subcom)
}
void
set_constructor_command(CLI::App* subcom)
set_constructor_command(CLI::App* subcom, mamba::Configuration& config)
{
init_constructor_parser(subcom);
init_constructor_parser(subcom, config);
subcom->callback(
[]
[&config]
{
auto& c = Configuration::instance();
auto& prefix = c.at("constructor_prefix").compute().value<fs::u8path>();
auto& extract_conda_pkgs = c.at("constructor_extract_conda_pkgs").compute().value<bool>();
auto& extract_tarball = c.at("constructor_extract_tarball").compute().value<bool>();
construct(prefix, extract_conda_pkgs, extract_tarball);
auto& prefix = config.at("constructor_prefix").compute().value<fs::u8path>();
auto& extract_conda_pkgs = config.at("constructor_extract_conda_pkgs")
.compute()
.value<bool>();
auto& extract_tarball = config.at("constructor_extract_tarball").compute().value<bool>();
construct(config, prefix, extract_conda_pkgs, extract_tarball);
}
);
}
void
construct(const fs::u8path& prefix, bool extract_conda_pkgs, bool extract_tarball)
construct(Configuration& config, const fs::u8path& prefix, bool extract_conda_pkgs, bool extract_tarball)
{
auto& config = Configuration::instance();
config.at("show_banner").set_value(false);
config.at("use_target_prefix_fallback").set_value(true);
config.at("target_prefix_checks")

View File

@ -12,10 +12,16 @@
namespace mamba
{
class ChannelContext;
class Configuration;
}
void
construct(const fs::u8path& prefix, bool extract_conda_pkgs, bool extract_tarball);
construct(
mamba::Configuration& config,
const fs::u8path& prefix,
bool extract_conda_pkgs,
bool extract_tarball
);
void
read_binary_from_stdin_and_write_to_file(fs::u8path& filename);

View File

@ -12,9 +12,9 @@
using namespace mamba; // NOLINT(build/namespaces)
void
set_create_command(CLI::App* subcom)
set_create_command(CLI::App* subcom, Configuration& config)
{
init_install_options(subcom);
init_install_options(subcom, config);
subcom->callback(mamba::create);
subcom->callback([&] { return mamba::create(config); });
}

View File

@ -41,30 +41,30 @@ get_env_name(const fs::u8path& px)
void
set_env_command(CLI::App* com)
set_env_command(CLI::App* com, Configuration& config)
{
init_general_options(com);
init_prefix_options(com);
init_general_options(com, config);
init_prefix_options(com, config);
auto* list_subcom = com->add_subcommand("list", "List known environments");
init_general_options(list_subcom);
init_prefix_options(list_subcom);
init_general_options(list_subcom, config);
init_prefix_options(list_subcom, config);
auto* create_subcom = com->add_subcommand(
"create",
"Create new environment (pre-commit.com compatibility alias for 'micromamba create')"
);
init_install_options(create_subcom);
init_install_options(create_subcom, config);
static bool explicit_format;
static bool no_md5;
static bool explicit_format = false;
static bool no_md5 = false;
static bool no_build = false;
static bool from_history = false;
auto* export_subcom = com->add_subcommand("export", "Export environment");
init_general_options(export_subcom);
init_prefix_options(export_subcom);
init_general_options(export_subcom, config);
init_prefix_options(export_subcom, config);
export_subcom->add_flag("-e,--explicit", explicit_format, "Use explicit format");
export_subcom->add_flag("--no-md5,!--md5", no_md5, "Disable md5");
export_subcom->add_flag("--no-build,!--build", no_build, "Disable the build string in spec");
@ -78,7 +78,6 @@ set_env_command(CLI::App* com)
[&]
{
auto const& ctx = Context::instance();
auto& config = Configuration::instance();
config.at("show_banner").set_value(false);
config.load();
@ -154,10 +153,9 @@ set_env_command(CLI::App* com)
);
list_subcom->callback(
[]
[&config]
{
const auto& ctx = Context::instance();
auto& config = Configuration::instance();
config.load();
EnvironmentsManager env_manager;
@ -195,16 +193,16 @@ set_env_command(CLI::App* com)
);
auto* remove_subcom = com->add_subcommand("remove", "Remove an environment");
init_general_options(remove_subcom);
init_prefix_options(remove_subcom);
init_general_options(remove_subcom, config);
init_prefix_options(remove_subcom, config);
create_subcom->callback(mamba::create);
create_subcom->callback([&] { return mamba::create(config); });
remove_subcom->callback(
[]
[&config]
{
// Remove specs if exist
remove(MAMBA_REMOVE_ALL);
remove(config, MAMBA_REMOVE_ALL);
const auto& ctx = Context::instance();
if (!ctx.dry_run)

View File

@ -9,26 +9,23 @@
#include "common_options.hpp"
using namespace mamba; // NOLINT(build/namespaces)
void
init_info_parser(CLI::App* subcom)
init_info_parser(CLI::App* subcom, mamba::Configuration& config)
{
init_general_options(subcom);
init_prefix_options(subcom);
init_general_options(subcom, config);
init_prefix_options(subcom, config);
}
void
set_info_command(CLI::App* subcom)
set_info_command(CLI::App* subcom, mamba::Configuration& config)
{
init_info_parser(subcom);
init_info_parser(subcom, config);
static bool print_licenses;
subcom->add_flag("--licenses", print_licenses, "Print licenses");
subcom->callback(
[]
[&config]
{
// TODO: Print full license texts.
if (print_licenses)
@ -73,7 +70,7 @@ set_info_command(CLI::App* subcom)
}
else
{
info();
info(config);
}
}
);

View File

@ -9,11 +9,9 @@ using namespace mamba; // NOLINT(build/namespaces)
void
set_install_command(CLI::App* subcom)
set_install_command(CLI::App* subcom, Configuration& config)
{
init_install_options(subcom);
auto& config = Configuration::instance();
init_install_options(subcom, config);
auto& freeze_installed = config.at("freeze_installed");
subcom->add_flag(
@ -28,5 +26,5 @@ set_install_command(CLI::App* subcom)
force_reinstall.description()
);
subcom->callback(mamba::install);
subcom->callback([&] { return mamba::install(config); });
}

View File

@ -13,12 +13,10 @@
using namespace mamba; // NOLINT(build/namespaces)
void
init_list_parser(CLI::App* subcom)
init_list_parser(CLI::App* subcom, Configuration& config)
{
init_general_options(subcom);
init_prefix_options(subcom);
auto& config = Configuration::instance();
init_general_options(subcom, config);
init_prefix_options(subcom, config);
auto& regex = config.insert(Configurable("list_regex", std::string(""))
.group("cli")
@ -27,16 +25,15 @@ init_list_parser(CLI::App* subcom)
}
void
set_list_command(CLI::App* subcom)
set_list_command(CLI::App* subcom, Configuration& config)
{
init_list_parser(subcom);
init_list_parser(subcom, config);
subcom->callback(
[]
[&config]
{
auto& config = Configuration::instance();
auto& regex = config.at("list_regex").compute().value<std::string>();
list(regex);
list(config, regex);
}
);
}

View File

@ -34,6 +34,7 @@ int
main(int argc, char** argv)
{
mamba::MainExecutor scoped_threads;
mamba::Configuration config;
init_console();
auto& ctx = Context::instance();
@ -42,7 +43,7 @@ main(int argc, char** argv)
ctx.command_params.custom_banner = banner;
CLI::App app{ "Version: " + version() + "\n" };
set_umamba_command(&app);
set_umamba_command(&app, config);
char** utf8argv;
@ -67,7 +68,7 @@ main(int argc, char** argv)
if (argc >= 2 && strcmp(argv[1], "completer") == 0)
{
get_completions(&app, argc, utf8argv);
get_completions(&app, config, argc, utf8argv);
reset_console();
return 0;
}
@ -89,13 +90,13 @@ main(int argc, char** argv)
CLI11_PARSE(app, argc, utf8argv);
if (app.get_subcommands().size() == 0)
{
Configuration::instance().load();
config.load();
Console::instance().print(app.help());
}
if (app.got_subcommand("config")
&& app.get_subcommand("config")->get_subcommands().size() == 0)
{
Configuration::instance().load();
config.load();
Console::instance().print(app.get_subcommand("config")->help());
}
}

View File

@ -13,23 +13,23 @@
using namespace mamba; // NOLINT(build/namespaces)
void
set_package_command(CLI::App* subcom)
set_package_command(CLI::App* subcom, Configuration& config)
{
static std::string infile, dest;
static int compression_level = -1;
static int compression_threads = 1;
init_general_options(subcom);
init_general_options(subcom, config);
auto extract_subcom = subcom->add_subcommand("extract");
init_general_options(extract_subcom);
init_general_options(extract_subcom, config);
extract_subcom->add_option("archive", infile, "Archive to extract");
extract_subcom->add_option("dest", dest, "Destination folder");
extract_subcom->callback(
[&]()
[&]
{
// load verbose and other options to context
Configuration::instance().load();
config.load();
Console::stream() << "Extracting " << fs::absolute(infile) << " to "
<< fs::absolute(dest) << std::endl;
@ -38,7 +38,7 @@ set_package_command(CLI::App* subcom)
);
auto compress_subcom = subcom->add_subcommand("compress");
init_general_options(compress_subcom);
init_general_options(compress_subcom, config);
compress_subcom->add_option("folder", infile, "Folder to compress");
compress_subcom->add_option("dest", dest, "Destination (e.g. myfile-3.1-0.tar.bz2 or .conda)");
compress_subcom->add_option(
@ -55,7 +55,7 @@ set_package_command(CLI::App* subcom)
[&]()
{
// load verbose and other options to context
Configuration::instance().load();
config.load();
Console::stream() << "Compressing " << fs::absolute(infile) << " to " << dest
<< std::endl;
@ -79,7 +79,7 @@ set_package_command(CLI::App* subcom)
);
auto transmute_subcom = subcom->add_subcommand("transmute");
init_general_options(transmute_subcom);
init_general_options(transmute_subcom, config);
transmute_subcom->add_option("infile", infile, "Folder to compress");
transmute_subcom->add_option(
"-c,--compression-level",
@ -95,7 +95,7 @@ set_package_command(CLI::App* subcom)
[&]()
{
// load verbose and other options to context
Configuration::instance().load();
config.load();
if (ends_with(infile, ".tar.bz2"))
{

View File

@ -13,13 +13,11 @@
using namespace mamba; // NOLINT(build/namespaces)
void
set_remove_command(CLI::App* subcom)
set_remove_command(CLI::App* subcom, Configuration& config)
{
using string_list = std::vector<std::string>;
init_general_options(subcom);
init_prefix_options(subcom);
auto& config = Configuration::instance();
init_general_options(subcom, config);
init_prefix_options(subcom, config);
auto& specs = config.at("specs");
subcom->add_option(
@ -38,7 +36,7 @@ set_remove_command(CLI::App* subcom)
subcom->add_flag("--prune,!--no-prune", prune, "Prune dependencies (default)");
subcom->callback(
[]
[&config]
{
int flags = 0;
if (prune)
@ -53,7 +51,7 @@ set_remove_command(CLI::App* subcom)
{
flags |= MAMBA_REMOVE_ALL;
}
remove(flags);
remove(config, flags);
}
);
}

View File

@ -9,35 +9,31 @@
#include "common_options.hpp"
using namespace mamba; // NOLINT(build/namespaces)
QueryType
mamba::QueryType
str_to_qtype(const std::string& s)
{
if (s == "search")
{
return QueryType::kSEARCH;
return mamba::QueryType::kSEARCH;
}
if (s == "depends")
{
return QueryType::kDEPENDS;
return mamba::QueryType::kDEPENDS;
}
if (s == "whoneeds")
{
return QueryType::kWHONEEDS;
return mamba::QueryType::kWHONEEDS;
}
throw std::runtime_error("Could not parse query type");
}
void
set_common_search(CLI::App* subcom, bool is_repoquery)
set_common_search(CLI::App* subcom, mamba::Configuration& config, bool is_repoquery)
{
auto& config = Configuration::instance();
init_general_options(subcom);
init_prefix_options(subcom);
init_network_options(subcom);
init_channel_parser(subcom);
init_general_options(subcom, config);
init_prefix_options(subcom, config);
init_network_options(subcom, config);
init_channel_parser(subcom, config);
static std::string query_type;
if (is_repoquery)
@ -81,6 +77,8 @@ set_common_search(CLI::App* subcom, bool is_repoquery)
subcom->callback(
[&]
{
using namespace mamba;
auto qtype = str_to_qtype(query_type);
QueryResultFormat format = QueryResultFormat::kTABLE;
bool use_local = true;
@ -122,19 +120,19 @@ set_common_search(CLI::App* subcom, bool is_repoquery)
auto& channels = config.at("channels").compute().value<std::vector<std::string>>();
use_local = use_local && channels.empty();
repoquery(qtype, format, use_local, specs[0]);
repoquery(config, qtype, format, use_local, specs[0]);
}
);
}
void
set_search_command(CLI::App* subcom)
set_search_command(CLI::App* subcom, mamba::Configuration& config)
{
set_common_search(subcom, false);
set_common_search(subcom, config, false);
}
void
set_repoquery_command(CLI::App* subcom)
set_repoquery_command(CLI::App* subcom, mamba::Configuration& config)
{
set_common_search(subcom, true);
set_common_search(subcom, config, true);
}

View File

@ -134,9 +134,9 @@ set_ps_command(CLI::App* subcom)
}
void
set_run_command(CLI::App* subcom)
set_run_command(CLI::App* subcom, Configuration& config)
{
init_prefix_options(subcom);
init_prefix_options(subcom, config);
static std::string streams;
CLI::Option* stream_option = subcom
@ -176,9 +176,8 @@ set_run_command(CLI::App* subcom)
static reproc::process proc;
subcom->callback(
[subcom, stream_option]()
[&config, subcom, stream_option]()
{
auto& config = Configuration::instance();
config.at("show_banner").set_value(false);
config.load();

View File

@ -169,9 +169,8 @@ handle_solve_request(
int
run_server(int port, mamba::ChannelContext& channel_context)
run_server(int port, mamba::ChannelContext& channel_context, Configuration& config)
{
auto& config = mamba::Configuration::instance();
config.load();
std::signal(SIGPIPE, SIG_IGN);
auto server_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
@ -209,18 +208,18 @@ run_server(int port, mamba::ChannelContext& channel_context)
}
void
set_server_command(CLI::App* subcom)
set_server_command(CLI::App* subcom, mamba::Configuration& config)
{
init_general_options(subcom);
init_general_options(subcom, config);
static int port = 1234;
subcom->add_option("--port,-p", port, "The port to use for the server");
subcom->callback(
[]
[&config]
{
mamba::ChannelContext channel_context;
return run_server(port, channel_context);
return run_server(port, channel_context, config);
}
);
}

View File

@ -160,13 +160,12 @@ namespace
void set_shell_init_command(CLI::App* subsubcmd, Configuration& config)
{
init_general_options(subsubcmd);
init_general_options(subsubcmd, config);
init_shell_option(subsubcmd, config);
init_root_prefix_option(subsubcmd, config);
subsubcmd->callback(
[]()
[&config]()
{
auto& config = Configuration::instance();
set_default_config_options(config);
config.load();
shell_init(
@ -180,13 +179,12 @@ namespace
void set_shell_deinit_command(CLI::App* subsubcmd, Configuration& config)
{
init_general_options(subsubcmd);
init_general_options(subsubcmd, config);
init_shell_option(subsubcmd, config);
init_root_prefix_option(subsubcmd, config);
subsubcmd->callback(
[]()
[&config]()
{
auto& config = Configuration::instance();
set_default_config_options(config);
config.load();
shell_deinit(
@ -200,12 +198,11 @@ namespace
void set_shell_reinit_command(CLI::App* subsubcmd, Configuration& config)
{
init_general_options(subsubcmd);
init_general_options(subsubcmd, config);
init_shell_option(subsubcmd, config);
subsubcmd->callback(
[]()
[&config]()
{
auto& config = Configuration::instance();
set_default_config_options(config);
config.load();
shell_reinit(Context::instance().prefix_params.root_prefix);
@ -216,13 +213,12 @@ namespace
void set_shell_hook_command(CLI::App* subsubcmd, Configuration& config)
{
init_general_options(subsubcmd);
init_general_options(subsubcmd, config);
init_shell_option(subsubcmd, config);
init_root_prefix_option(subsubcmd, config); // FIXME not used here set in CLI scripts
subsubcmd->callback(
[]()
[&config]()
{
auto& config = Configuration::instance();
set_default_config_options(config);
config.load();
shell_hook(consolidate_shell(config.at("shell_type").compute().value<std::string>()));
@ -233,15 +229,14 @@ namespace
void set_shell_activate_command(CLI::App* subsubcmd, Configuration& config)
{
init_general_options(subsubcmd);
init_general_options(subsubcmd, config);
init_shell_option(subsubcmd, config);
init_prefix_options(subsubcmd, config);
init_stack_option(subsubcmd, config);
subsubcmd->callback(
[]()
[&config]()
{
auto& config = Configuration::instance();
set_default_config_options(config);
consolidate_prefix_options(config);
config.load();
@ -257,12 +252,11 @@ namespace
void set_shell_reactivate_command(CLI::App* subsubcmd, Configuration& config)
{
init_general_options(subsubcmd);
init_general_options(subsubcmd, config);
init_shell_option(subsubcmd, config);
subsubcmd->callback(
[]()
[&config]()
{
auto& config = Configuration::instance();
set_default_config_options(config);
config.load();
shell_reactivate(
@ -275,12 +269,11 @@ namespace
void set_shell_deactivate_command(CLI::App* subsubcmd, Configuration& config)
{
init_general_options(subsubcmd);
init_general_options(subsubcmd, config);
init_shell_option(subsubcmd, config);
subsubcmd->callback(
[]()
[&config]()
{
auto& config = Configuration::instance();
set_default_config_options(config);
config.load();
shell_deactivate(config.at("shell_type").compute().value<std::string>());
@ -289,13 +282,12 @@ namespace
);
}
void set_shell_long_path_command(CLI::App* subsubcmd)
void set_shell_long_path_command(CLI::App* subsubcmd, mamba::Configuration& config)
{
init_general_options(subsubcmd);
init_general_options(subsubcmd, config);
subsubcmd->callback(
[]()
[&config]()
{
auto& config = Configuration::instance();
set_default_config_options(config);
config.load();
shell_enable_long_path_support();
@ -309,16 +301,17 @@ namespace
***********************/
template <typename Arr>
void set_shell_launch_command(CLI::App* subcmd, const Arr& all_subsubcmds, Configuration& config)
void
set_shell_launch_command(CLI::App* subcmd, const Arr& all_subsubcmds, mamba::Configuration& config)
{
// The initial parser had the subcmdmand as an action so both
// ``micromamba shell init --shell bash`` and ``micromamba shell --shell bash init`` were
// allowed.
init_general_options(subcmd);
init_general_options(subcmd, config);
init_prefix_options(subcmd, config);
subcmd->callback(
[all_subsubcmds]()
[all_subsubcmds, &config]()
{
bool const got_subsubcmd = std::any_of(
all_subsubcmds.cbegin(),
@ -329,7 +322,6 @@ namespace
// because this callback may be greedily executed, even with a sub sub command.
if (!got_subsubcmd)
{
auto& config = Configuration::instance();
set_default_config_options(config);
consolidate_prefix_options(config);
config.load();
@ -364,10 +356,8 @@ namespace
}
void
set_shell_command(CLI::App* shell_subcmd)
set_shell_command(CLI::App* shell_subcmd, Configuration& config)
{
auto& config = Configuration::instance();
auto* init_subsubcmd = shell_subcmd->add_subcommand(
"init",
"Add initialization in script to rc files"
@ -411,7 +401,7 @@ set_shell_command(CLI::App* shell_subcmd)
"enable_long_path_support",
"Output deactivation code for the given shell"
);
set_shell_long_path_command(long_path_subsubcmd);
set_shell_long_path_command(long_path_subsubcmd, config);
// `micromamba shell` is used to launch a new shell
// TODO micromamba 2.0 rename this command (e.g. start-shell) or the other to avoid

View File

@ -4,6 +4,7 @@
//
// The full license is in the file LICENSE, distributed with this software.
#include "mamba/api/configuration.hpp"
#include "mamba/core/channel.hpp"
#include "mamba/core/context.hpp"
#include "mamba/version.hpp"
@ -15,16 +16,16 @@
using namespace mamba; // NOLINT(build/namespaces)
void
init_umamba_options(CLI::App* subcom)
init_umamba_options(CLI::App* subcom, Configuration& config)
{
init_general_options(subcom);
init_prefix_options(subcom);
init_general_options(subcom, config);
init_prefix_options(subcom, config);
}
void
set_umamba_command(CLI::App* com)
set_umamba_command(CLI::App* com, mamba::Configuration& config)
{
init_umamba_options(com);
init_umamba_options(com, config);
Context::instance().command_params.caller_version = umamba::version();
@ -37,61 +38,61 @@ set_umamba_command(CLI::App* com)
com->add_flag_function("--version", print_version);
CLI::App* shell_subcom = com->add_subcommand("shell", "Generate shell init scripts");
set_shell_command(shell_subcom);
set_shell_command(shell_subcom, config);
CLI::App* create_subcom = com->add_subcommand("create", "Create new environment");
set_create_command(create_subcom);
set_create_command(create_subcom, config);
CLI::App* install_subcom = com->add_subcommand("install", "Install packages in active environment");
set_install_command(install_subcom);
set_install_command(install_subcom, config);
CLI::App* update_subcom = com->add_subcommand("update", "Update packages in active environment");
set_update_command(update_subcom);
set_update_command(update_subcom, config);
CLI::App* self_update_subcom = com->add_subcommand("self-update", "Update micromamba");
set_self_update_command(self_update_subcom);
set_self_update_command(self_update_subcom, config);
CLI::App* repoquery_subcom = com->add_subcommand(
"repoquery",
"Find and analyze packages in active environment or channels"
);
set_repoquery_command(repoquery_subcom);
set_repoquery_command(repoquery_subcom, config);
CLI::App* remove_subcom = com->add_subcommand("remove", "Remove packages from active environment");
set_remove_command(remove_subcom);
set_remove_command(remove_subcom, config);
CLI::App* list_subcom = com->add_subcommand("list", "List packages in active environment");
set_list_command(list_subcom);
set_list_command(list_subcom, config);
CLI::App* package_subcom = com->add_subcommand(
"package",
"Extract a package or bundle files into an archive"
);
set_package_command(package_subcom);
set_package_command(package_subcom, config);
CLI::App* clean_subcom = com->add_subcommand("clean", "Clean package cache");
set_clean_command(clean_subcom);
set_clean_command(clean_subcom, config);
CLI::App* config_subcom = com->add_subcommand("config", "Configuration of micromamba");
set_config_command(config_subcom);
set_config_command(config_subcom, config);
CLI::App* info_subcom = com->add_subcommand("info", "Information about micromamba");
set_info_command(info_subcom);
set_info_command(info_subcom, config);
CLI::App* constructor_subcom = com->add_subcommand(
"constructor",
"Commands to support using micromamba in constructor"
);
set_constructor_command(constructor_subcom);
set_constructor_command(constructor_subcom, config);
CLI::App* env_subcom = com->add_subcommand("env", "List environments");
set_env_command(env_subcom);
set_env_command(env_subcom, config);
CLI::App* activate_subcom = com->add_subcommand("activate", "Activate an environment");
set_activate_command(activate_subcom);
CLI::App* run_subcom = com->add_subcommand("run", "Run an executable in an environment");
set_run_command(run_subcom);
set_run_command(run_subcom, config);
CLI::App* ps_subcom = com->add_subcommand("ps", "Show, inspect or kill running processes");
set_ps_command(ps_subcom);
@ -103,11 +104,11 @@ set_umamba_command(CLI::App* com)
"search",
"Find packages in active environment or channels"
);
set_search_command(search_subcom);
set_search_command(search_subcom, config);
#if !defined(_WIN32) && defined(MICROMAMBA_SERVER)
CLI::App* server_subcom = com->add_subcommand("server", "Run micromamba server");
set_server_command(server_subcom);
set_server_command(server_subcom, config);
#endif
com->require_subcommand(/* min */ 0, /* max */ 1);

View File

@ -20,71 +20,71 @@ const char banner[] = R"MAMBARAW(
)MAMBARAW";
void
set_clean_command(CLI::App* subcom);
set_clean_command(CLI::App* subcom, mamba::Configuration& config);
void
set_config_command(CLI::App* subcom);
set_config_command(CLI::App* subcom, mamba::Configuration& config);
void
set_constructor_command(CLI::App* subcom);
set_constructor_command(CLI::App* subcom, mamba::Configuration& config);
void
set_create_command(CLI::App* subcom);
set_create_command(CLI::App* subcom, mamba::Configuration& config);
void
set_info_command(CLI::App* subcom);
set_info_command(CLI::App* subcom, mamba::Configuration& config);
void
set_install_command(CLI::App* subcom);
set_install_command(CLI::App* subcom, mamba::Configuration& config);
void
set_list_command(CLI::App* subcom);
set_list_command(CLI::App* subcom, mamba::Configuration& config);
void
set_remove_command(CLI::App* subcom);
set_remove_command(CLI::App* subcom, mamba::Configuration& config);
void
set_shell_command(CLI::App* subcom);
set_shell_command(CLI::App* subcom, mamba::Configuration& config);
void
set_package_command(CLI::App* subcom);
set_package_command(CLI::App* subcom, mamba::Configuration& config);
void
set_umamba_command(CLI::App* com);
set_umamba_command(CLI::App* com, mamba::Configuration& config);
void
set_update_command(CLI::App* subcom);
set_update_command(CLI::App* subcom, mamba::Configuration& config);
void
set_self_update_command(CLI::App* subcom);
set_self_update_command(CLI::App* subcom, mamba::Configuration& config);
void
set_repoquery_command(CLI::App* subcom);
set_repoquery_command(CLI::App* subcom, mamba::Configuration& config);
void
set_env_command(CLI::App* subcom);
set_env_command(CLI::App* subcom, mamba::Configuration& config);
void
set_activate_command(CLI::App* subcom);
void
set_run_command(CLI::App* subcom);
set_run_command(CLI::App* subcom, mamba::Configuration& config);
void
set_ps_command(CLI::App* subcom);
void
get_completions(CLI::App* app, int argc, char** argv);
get_completions(CLI::App* app, mamba::Configuration& config, int argc, char** argv);
void
set_search_command(CLI::App* subcom);
set_search_command(CLI::App* subcom, mamba::Configuration& config);
void
set_auth_command(CLI::App* subcom);
#if !defined(_WIN32) && defined(MICROMAMBA_SERVER)
void
set_server_command(CLI::App* subcom);
set_server_command(CLI::App* subcom, mamba::Configuration& config);
#endif
#endif

View File

@ -23,9 +23,8 @@
using namespace mamba; // NOLINT(build/namespaces)
int
update_self(const std::optional<std::string>& version)
update_self(Configuration& config, const std::optional<std::string>& version)
{
auto& config = mamba::Configuration::instance();
auto& ctx = mamba::Context::instance();
config.load();
@ -164,11 +163,9 @@ update_self(const std::optional<std::string>& version)
void
set_update_command(CLI::App* subcom)
set_update_command(CLI::App* subcom, Configuration& config)
{
Configuration::instance();
init_install_options(subcom);
init_install_options(subcom, config);
static bool prune = true;
static bool update_all = false;
@ -177,18 +174,16 @@ set_update_command(CLI::App* subcom)
subcom->get_option("specs")->description("Specs to update in the environment");
subcom->add_flag("-a,--all", update_all, "Update all packages in the environment");
subcom->callback([&] { return update(update_all, prune); });
subcom->callback([&] { return update(config, update_all, prune); });
}
void
set_self_update_command(CLI::App* subcom)
set_self_update_command(CLI::App* subcom, Configuration& config)
{
Configuration::instance();
init_install_options(subcom);
init_install_options(subcom, config);
static std::optional<std::string> version;
subcom->add_option("--version", version, "Install specific micromamba version");
subcom->callback([&] { return update_self(version); });
subcom->callback([&] { return update_self(config, version); });
}