Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support CONDA_DEFAULT_ENV #3445

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libmamba/src/api/clean.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
3 changes: 3 additions & 0 deletions libmamba/src/api/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
45 changes: 31 additions & 14 deletions libmamba/src/api/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 = "\\";
Expand Down Expand Up @@ -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")
Expand All @@ -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" })
Expand Down
1 change: 1 addition & 0 deletions libmamba/src/api/create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions libmamba/src/api/info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions libmamba/src/api/install.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions libmamba/src/api/list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions libmamba/src/api/remove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions libmamba/src/api/repoquery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions libmamba/src/api/update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 5 additions & 0 deletions micromamba/src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions micromamba/src/constructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions micromamba/src/shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions micromamba/tests/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions micromamba/tests/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def config_tests(cls, res, root_prefix=root_prefix, target_prefix=prefix):
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
Expand Down
1 change: 1 addition & 0 deletions micromamba/tests/test_remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions micromamba/tests/test_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]


Expand Down
1 change: 1 addition & 0 deletions micromamba/tests/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ def config_tests(cls, res, root_prefix=root_prefix, target_prefix=prefix):
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
Expand Down
Loading