Skip to content

Commit

Permalink
fix: Honour CONDA_ENVS_PATH again
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Jerphanion <git@jjerphan.xyz>
  • Loading branch information
jjerphan committed Jan 3, 2025
1 parent c9c4580 commit 5fb254d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
13 changes: 13 additions & 0 deletions libmamba/src/api/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,19 @@ namespace mamba
dirs.push_back(default_env_dir);
}

// Also add all the directories in the environment variable `CONDA_ENVS_PATH`.
auto conda_envs_path = util::get_env("CONDA_ENVS_PATH");
if (conda_envs_path)
{
auto paths_separator = util::pathsep();

auto paths = util::split(conda_envs_path.value(), paths_separator);
for (auto& p : paths)
{
dirs.push_back(fs::u8path(p));
}
}

// Check that the values exist as directories
for (auto& d : dirs)
{
Expand Down
24 changes: 24 additions & 0 deletions libmamba/tests/src/core/test_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,30 @@ namespace mamba
);
}

TEST_CASE_METHOD(Configuration, "envs_dirs_with_env_variable")
{
std::string cache1 = util::path_concat(util::user_home_dir(), "foo_envs_dirs");
std::string cache2 = util::path_concat(util::user_home_dir(), "bar_envs_dirs");

// Set CONDA_ENVS_PATH with cache1 and cache2 using platform specific path separator
util::set_env("CONDA_ENVS_PATH", cache1 + util::pathsep() + cache2);

// Load default config to get the envs_dirs
config.load();

const auto& envs_dirs = config.at("envs_dirs").value<std::vector<fs::u8path>>();

std::set<fs::u8path> envs_dirs_set(envs_dirs.begin(), envs_dirs.end());

// `envs_dirs` should at least contain `root_prefix / envs`, `cache1` and `cache2`
REQUIRE(envs_dirs.size() >= 3);
REQUIRE(envs_dirs_set.find(get_root_prefix_envs_dir()) != envs_dirs_set.end());
REQUIRE(envs_dirs_set.find(cache1) != envs_dirs_set.end());
REQUIRE(envs_dirs_set.find(cache2) != envs_dirs_set.end());

util::unset_env("CONDA_ENVS_PATH");
}

TEST_CASE_METHOD(Configuration, "pkgs_dirs")
{
std::string cache1 = util::path_concat(util::user_home_dir(), "foo");
Expand Down

0 comments on commit 5fb254d

Please sign in to comment.