Skip to content

Commit

Permalink
Always add root_prefix/envs in envs_dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
Hind-M committed Dec 16, 2024
1 parent bb38a69 commit 0c40a1b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 11 deletions.
21 changes: 13 additions & 8 deletions libmamba/src/api/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -965,13 +965,18 @@ namespace mamba
}
}

std::vector<fs::u8path> fallback_envs_dirs_hook(const Context& context)
void envs_dirs_hook(const Context& context, std::vector<fs::u8path>& dirs)
{
return { context.prefix_params.root_prefix / "envs" };
}
// Check that "root_prefix/envs" is already in the dirs,
// and append if not - to match `conda`
// Therefore, there is no need for a fallback value anymore
fs::u8path default_env_dir = context.prefix_params.root_prefix / "envs";
if (std::find(dirs.begin(), dirs.end(), default_env_dir) == dirs.end())
{
dirs.push_back(default_env_dir);
}

void envs_dirs_hook(std::vector<fs::u8path>& dirs)
{
// Check that the values exist as directories
for (auto& d : dirs)
{
d = fs::weakly_canonical(util::expand_home(d.string())).string();
Expand Down Expand Up @@ -1297,10 +1302,10 @@ namespace mamba
.set_rc_configurable(RCConfigLevel::kHomeDir)
.set_env_var_names({ "CONDA_ENVS_DIRS" })
.needs({ "root_prefix" })
.set_fallback_value_hook<decltype(m_context.envs_dirs)>(
[this] { return detail::fallback_envs_dirs_hook(m_context); }
.set_post_merge_hook<decltype(m_context.envs_dirs)>(
[this](decltype(m_context.envs_dirs)& value)
{ return detail::envs_dirs_hook(m_context, value); }
)
.set_post_merge_hook(detail::envs_dirs_hook)
.description("Possible locations of named environments"));

insert(Configurable("pkgs_dirs", &m_context.pkgs_dirs)
Expand Down
34 changes: 34 additions & 0 deletions libmamba/tests/src/core/test_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,40 @@ namespace mamba
- https://repo.mamba.pm/conda-forge)"));
}

TEST_CASE_METHOD(Configuration, "envs_dirs")
{
// Load default config
// `envs_dirs` should be set to `root_prefix / envs`
config.load();

const auto& envs_dirs = config.at("envs_dirs").value<std::vector<fs::u8path>>();
REQUIRE(envs_dirs.size() == 1);
REQUIRE(
envs_dirs[0]
== util::path_concat(
std::string(config.at("root_prefix").value<mamba::fs::u8path>()),
"envs"
)
);
}

TEST_CASE_METHOD(Configuration, "envs_dirs_with_additional_rc")
{
std::string cache1 = util::path_concat(util::user_home_dir(), "foo_envs_dirs");
std::string rc1 = "envs_dirs:\n - " + cache1;

load_test_config(rc1);

REQUIRE(
config.dump()
== "envs_dirs:\n - " + cache1 + "\n - "
+ util::path_concat(
std::string(config.at("root_prefix").value<mamba::fs::u8path>()),
"envs"
)
);
}

TEST_CASE_METHOD(Configuration, "pkgs_dirs")
{
std::string cache1 = util::path_concat(util::user_home_dir(), "foo");
Expand Down
3 changes: 0 additions & 3 deletions micromamba/src/common_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ init_channel_parser(CLI::App* subcom, mamba::Configuration& config);
void
load_channel_options(mamba::Context& ctx);

void
channels_hook(std::vector<std::string>& channels);

void
override_channels_hook(mamba::Configuration& config, bool& override_channels);

Expand Down

0 comments on commit 0c40a1b

Please sign in to comment.