mirror of https://github.com/mamba-org/mamba.git
Support CONDA_DEFAULT_ENV (#3445)
* Support CONDA_DEFAULT_ENV * Fix test
This commit is contained in:
parent
fc06ae8bbc
commit
6db44c8a64
|
@ -23,6 +23,7 @@ namespace mamba
|
|||
auto& ctx = config.context();
|
||||
|
||||
config.at("use_target_prefix_fallback").set_value(true);
|
||||
config.at("use_default_prefix_fallback").set_value(true);
|
||||
config.at("use_root_prefix_fallback").set_value(true);
|
||||
config.load();
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ namespace mamba
|
|||
void config_describe(Configuration& config)
|
||||
{
|
||||
config.at("use_target_prefix_fallback").set_value(true);
|
||||
config.at("use_default_prefix_fallback").set_value(true);
|
||||
config.at("use_root_prefix_fallback").set_value(true);
|
||||
config.at("target_prefix_checks")
|
||||
.set_value(
|
||||
|
@ -38,6 +39,7 @@ namespace mamba
|
|||
void config_list(Configuration& config)
|
||||
{
|
||||
config.at("use_target_prefix_fallback").set_value(true);
|
||||
config.at("use_default_prefix_fallback").set_value(true);
|
||||
config.at("use_root_prefix_fallback").set_value(true);
|
||||
config.at("target_prefix_checks")
|
||||
.set_value(
|
||||
|
@ -70,6 +72,7 @@ namespace mamba
|
|||
void config_sources(Configuration& config)
|
||||
{
|
||||
config.at("use_target_prefix_fallback").set_value(true);
|
||||
config.at("use_default_prefix_fallback").set_value(true);
|
||||
config.at("use_root_prefix_fallback").set_value(true);
|
||||
config.at("target_prefix_checks")
|
||||
.set_value(
|
||||
|
|
|
@ -567,10 +567,33 @@ namespace mamba
|
|||
|
||||
void target_prefix_hook(Configuration& config, fs::u8path& prefix)
|
||||
{
|
||||
// Fall back to environment specified in CONDA_PREFIX
|
||||
bool use_target_prefix_fallback = config.at("use_target_prefix_fallback").value<bool>();
|
||||
if (prefix.empty() && use_target_prefix_fallback)
|
||||
{
|
||||
// CONDA_PREFIX is always a complete path
|
||||
prefix = util::get_env("CONDA_PREFIX").value_or("");
|
||||
}
|
||||
|
||||
// Fall back to environment specified in CONDA_DEFAULT_ENV
|
||||
bool use_default_prefix_fallback = config.at("use_default_prefix_fallback").value<bool>();
|
||||
if (prefix.empty() && use_default_prefix_fallback)
|
||||
{
|
||||
prefix = util::get_env("CONDA_DEFAULT_ENV").value_or("");
|
||||
}
|
||||
|
||||
// Fall back to base environment
|
||||
bool use_root_prefix_fallback = config.at("use_root_prefix_fallback").value<bool>();
|
||||
if (prefix.empty() && use_root_prefix_fallback)
|
||||
{
|
||||
prefix = config.at("root_prefix").value<fs::u8path>();
|
||||
}
|
||||
|
||||
auto& root_prefix = config.at("root_prefix").value<fs::u8path>();
|
||||
|
||||
if (!prefix.empty())
|
||||
{
|
||||
// Prefix can be an environment name rather than a full path
|
||||
if (prefix.string().find_first_of("/\\") == std::string::npos)
|
||||
{
|
||||
std::string old_prefix = prefix.string();
|
||||
|
@ -586,20 +609,6 @@ namespace mamba
|
|||
.c_str());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bool use_target_prefix_fallback = config.at("use_target_prefix_fallback").value<bool>();
|
||||
if (use_target_prefix_fallback)
|
||||
{
|
||||
prefix = util::get_env("CONDA_PREFIX").value_or("");
|
||||
}
|
||||
|
||||
bool use_root_prefix_fallback = config.at("use_root_prefix_fallback").value<bool>();
|
||||
if (use_root_prefix_fallback && prefix.empty())
|
||||
{
|
||||
prefix = root_prefix;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
std::string sep = "\\";
|
||||
|
@ -1201,6 +1210,7 @@ namespace mamba
|
|||
"env_name",
|
||||
"spec_file_env_name",
|
||||
"use_target_prefix_fallback",
|
||||
"use_default_prefix_fallback",
|
||||
"use_root_prefix_fallback" })
|
||||
.set_single_op_lifetime()
|
||||
.description("Path to the target prefix")
|
||||
|
@ -1227,6 +1237,13 @@ namespace mamba
|
|||
.set_single_op_lifetime()
|
||||
.description("Fallback to the root prefix or not"));
|
||||
|
||||
insert(Configurable("use_default_prefix_fallback", true)
|
||||
.group("Basic")
|
||||
.set_single_op_lifetime()
|
||||
.description(
|
||||
"Fallback to the prefix specified with environment variable CONDA_DEFAULT_ENV or not"
|
||||
));
|
||||
|
||||
insert(Configurable("target_prefix_checks", MAMBA_NO_PREFIX_CHECK)
|
||||
.group("Basic")
|
||||
.needs({ "target_prefix", "rc_files" })
|
||||
|
|
|
@ -18,6 +18,7 @@ namespace mamba
|
|||
auto& ctx = config.context();
|
||||
|
||||
config.at("use_target_prefix_fallback").set_value(false);
|
||||
config.at("use_default_prefix_fallback").set_value(false);
|
||||
config.at("use_root_prefix_fallback").set_value(false);
|
||||
config.at("target_prefix_checks")
|
||||
.set_value(
|
||||
|
|
|
@ -26,6 +26,7 @@ namespace mamba
|
|||
void info(Configuration& config)
|
||||
{
|
||||
config.at("use_target_prefix_fallback").set_value(true);
|
||||
config.at("use_default_prefix_fallback").set_value(true);
|
||||
config.at("use_root_prefix_fallback").set_value(true);
|
||||
config.at("target_prefix_checks")
|
||||
.set_value(
|
||||
|
|
|
@ -220,6 +220,7 @@ namespace mamba
|
|||
|
||||
config.at("create_base").set_value(true);
|
||||
config.at("use_target_prefix_fallback").set_value(true);
|
||||
config.at("use_default_prefix_fallback").set_value(true);
|
||||
config.at("use_root_prefix_fallback").set_value(true);
|
||||
config.at("target_prefix_checks")
|
||||
.set_value(
|
||||
|
|
|
@ -18,6 +18,7 @@ namespace mamba
|
|||
void list(Configuration& config, const std::string& regex)
|
||||
{
|
||||
config.at("use_target_prefix_fallback").set_value(true);
|
||||
config.at("use_default_prefix_fallback").set_value(true);
|
||||
config.at("use_root_prefix_fallback").set_value(true);
|
||||
config.at("target_prefix_checks")
|
||||
.set_value(
|
||||
|
|
|
@ -27,6 +27,7 @@ namespace mamba
|
|||
bool remove_all = flags & MAMBA_REMOVE_ALL;
|
||||
|
||||
config.at("use_target_prefix_fallback").set_value(true);
|
||||
config.at("use_default_prefix_fallback").set_value(false);
|
||||
config.at("use_root_prefix_fallback").set_value(false);
|
||||
config.at("target_prefix_checks")
|
||||
.set_value(
|
||||
|
|
|
@ -25,6 +25,7 @@ namespace mamba
|
|||
repoquery_init(Context& ctx, Configuration& config, QueryResultFormat format, bool use_local)
|
||||
{
|
||||
config.at("use_target_prefix_fallback").set_value(true);
|
||||
config.at("use_default_prefix_fallback").set_value(true);
|
||||
config.at("use_root_prefix_fallback").set_value(true);
|
||||
config.at("target_prefix_checks")
|
||||
.set_value(MAMBA_ALLOW_EXISTING_PREFIX | MAMBA_ALLOW_MISSING_PREFIX);
|
||||
|
|
|
@ -132,6 +132,7 @@ namespace mamba
|
|||
auto& ctx = config.context();
|
||||
|
||||
config.at("use_target_prefix_fallback").set_value(true);
|
||||
config.at("use_default_prefix_fallback").set_value(true);
|
||||
config.at("use_root_prefix_fallback").set_value(true);
|
||||
config.at("target_prefix_checks")
|
||||
.set_value(
|
||||
|
|
|
@ -302,6 +302,7 @@ void
|
|||
set_sequence_to_rc(mamba::Configuration& config, const SequenceAddType& opt)
|
||||
{
|
||||
config.at("use_target_prefix_fallback").set_value(true);
|
||||
config.at("use_default_prefix_fallback").set_value(true);
|
||||
config.at("use_root_prefix_fallback").set_value(true);
|
||||
config.at("target_prefix_checks")
|
||||
.set_value(
|
||||
|
@ -357,6 +358,7 @@ set_config_remove_key_command(CLI::App* subcom, mamba::Configuration& config)
|
|||
[&]()
|
||||
{
|
||||
config.at("use_target_prefix_fallback").set_value(true);
|
||||
config.at("use_default_prefix_fallback").set_value(true);
|
||||
config.at("use_root_prefix_fallback").set_value(true);
|
||||
config.at("target_prefix_checks")
|
||||
.set_value(
|
||||
|
@ -421,6 +423,7 @@ set_config_remove_command(CLI::App* subcom, mamba::Configuration& config)
|
|||
[&]
|
||||
{
|
||||
config.at("use_target_prefix_fallback").set_value(true);
|
||||
config.at("use_default_prefix_fallback").set_value(true);
|
||||
config.at("use_root_prefix_fallback").set_value(true);
|
||||
config.at("target_prefix_checks")
|
||||
.set_value(
|
||||
|
@ -499,6 +502,7 @@ set_config_set_command(CLI::App* subcom, mamba::Configuration& config)
|
|||
[&]
|
||||
{
|
||||
config.at("use_target_prefix_fallback").set_value(true);
|
||||
config.at("use_default_prefix_fallback").set_value(true);
|
||||
config.at("use_root_prefix_fallback").set_value(true);
|
||||
config.at("target_prefix_checks")
|
||||
.set_value(
|
||||
|
@ -545,6 +549,7 @@ set_config_get_command(CLI::App* subcom, mamba::Configuration& config)
|
|||
[&]
|
||||
{
|
||||
config.at("use_target_prefix_fallback").set_value(true);
|
||||
config.at("use_default_prefix_fallback").set_value(true);
|
||||
config.at("use_root_prefix_fallback").set_value(true);
|
||||
config.at("target_prefix_checks")
|
||||
.set_value(
|
||||
|
|
|
@ -68,6 +68,7 @@ void
|
|||
construct(Configuration& config, const fs::u8path& prefix, bool extract_conda_pkgs, bool extract_tarball)
|
||||
{
|
||||
config.at("use_target_prefix_fallback").set_value(true);
|
||||
config.at("use_default_prefix_fallback").set_value(true);
|
||||
config.at("use_root_prefix_fallback").set_value(true);
|
||||
config.at("target_prefix_checks")
|
||||
.set_value(
|
||||
|
|
|
@ -104,6 +104,7 @@ namespace
|
|||
void set_default_config_options(Configuration& config)
|
||||
{
|
||||
config.at("use_target_prefix_fallback").set_value(false);
|
||||
config.at("use_default_prefix_fallback").set_value(false);
|
||||
config.at("use_root_prefix_fallback").set_value(false);
|
||||
config.at("target_prefix_checks").set_value(MAMBA_NO_PREFIX_CHECK);
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ def check_create_result(res, root_prefix, target_prefix):
|
|||
assert res["root_prefix"] == str(root_prefix)
|
||||
assert res["target_prefix"] == str(target_prefix)
|
||||
assert not res["use_target_prefix_fallback"]
|
||||
assert not res["use_default_prefix_fallback"]
|
||||
assert not res["use_root_prefix_fallback"]
|
||||
checks = (
|
||||
helpers.MAMBA_ALLOW_EXISTING_PREFIX
|
||||
|
|
|
@ -51,6 +51,7 @@ class TestInstall:
|
|||
assert res["root_prefix"] == root_prefix
|
||||
assert res["target_prefix"] == target_prefix
|
||||
assert res["use_target_prefix_fallback"]
|
||||
assert res["use_default_prefix_fallback"]
|
||||
assert res["use_root_prefix_fallback"]
|
||||
checks = (
|
||||
helpers.MAMBA_ALLOW_EXISTING_PREFIX
|
||||
|
@ -179,6 +180,7 @@ class TestInstall:
|
|||
|
||||
if not current_target_prefix_fallback:
|
||||
os.environ.pop("CONDA_PREFIX")
|
||||
os.environ.pop("CONDA_DEFAULT_ENV")
|
||||
else:
|
||||
os.environ["CONDA_PREFIX"] = p
|
||||
|
||||
|
@ -205,6 +207,7 @@ class TestInstall:
|
|||
# Get the actual set MAMBA_ROOT_PREFIX when setting up `TestInstall` class
|
||||
os.environ["MAMBA_DEFAULT_ROOT_PREFIX"] = os.environ.pop("MAMBA_ROOT_PREFIX")
|
||||
os.environ.pop("CONDA_PREFIX")
|
||||
os.environ.pop("CONDA_DEFAULT_ENV")
|
||||
|
||||
# Fallback on root prefix
|
||||
res = helpers.install(*cmd, "--print-config-only")
|
||||
|
@ -228,6 +231,7 @@ class TestInstall:
|
|||
|
||||
os.environ.pop("MAMBA_ROOT_PREFIX")
|
||||
os.environ.pop("CONDA_PREFIX")
|
||||
os.environ.pop("CONDA_DEFAULT_ENV")
|
||||
|
||||
# Fallback on root prefix
|
||||
res = helpers.install(*cmd, "--print-config-only")
|
||||
|
|
|
@ -180,6 +180,7 @@ def remove_config_common_assertions(res, root_prefix, target_prefix):
|
|||
assert res["root_prefix"] == str(root_prefix)
|
||||
assert res["target_prefix"] == str(target_prefix)
|
||||
assert res["use_target_prefix_fallback"]
|
||||
assert not res["use_default_prefix_fallback"]
|
||||
assert not res["use_root_prefix_fallback"]
|
||||
checks = (
|
||||
helpers.MAMBA_ALLOW_EXISTING_PREFIX
|
||||
|
|
|
@ -190,6 +190,7 @@ def test_activate_target_prefix_checks(tmp_home, tmp_root_prefix):
|
|||
res = helpers.shell("activate", "-p", tmp_root_prefix, "--print-config-only")
|
||||
assert res["target_prefix_checks"] == helpers.MAMBA_NO_PREFIX_CHECK
|
||||
assert not res["use_target_prefix_fallback"]
|
||||
assert not res["use_default_prefix_fallback"]
|
||||
assert not res["use_root_prefix_fallback"]
|
||||
|
||||
|
||||
|
|
|
@ -245,6 +245,7 @@ class TestUpdateConfig:
|
|||
assert res["root_prefix"] == root_prefix
|
||||
assert res["target_prefix"] == target_prefix
|
||||
assert res["use_target_prefix_fallback"]
|
||||
assert res["use_default_prefix_fallback"]
|
||||
assert res["use_root_prefix_fallback"]
|
||||
checks = (
|
||||
helpers.MAMBA_ALLOW_EXISTING_PREFIX
|
||||
|
@ -372,6 +373,7 @@ class TestUpdateConfig:
|
|||
|
||||
if not current_target_prefix_fallback:
|
||||
os.environ.pop("CONDA_PREFIX")
|
||||
os.environ.pop("CONDA_DEFAULT_ENV")
|
||||
else:
|
||||
os.environ["CONDA_PREFIX"] = p
|
||||
|
||||
|
@ -398,6 +400,7 @@ class TestUpdateConfig:
|
|||
# Get the actual set MAMBA_ROOT_PREFIX when setting up `TestUpdateConfig` class
|
||||
os.environ["MAMBA_DEFAULT_ROOT_PREFIX"] = os.environ.pop("MAMBA_ROOT_PREFIX")
|
||||
os.environ.pop("CONDA_PREFIX")
|
||||
os.environ.pop("CONDA_DEFAULT_ENV")
|
||||
|
||||
# Fallback on root prefix
|
||||
res = helpers.install(*cmd, "--print-config-only")
|
||||
|
@ -420,6 +423,7 @@ class TestUpdateConfig:
|
|||
|
||||
os.environ.pop("MAMBA_ROOT_PREFIX")
|
||||
os.environ.pop("CONDA_PREFIX")
|
||||
os.environ.pop("CONDA_DEFAULT_ENV")
|
||||
|
||||
# Fallback on root prefix
|
||||
res = helpers.install(*cmd, "--print-config-only")
|
||||
|
|
Loading…
Reference in New Issue