fix: Honour `CONDA_ENVS_PATH` again (#3725)

Signed-off-by: Julien Jerphanion <git@jjerphan.xyz>
This commit is contained in:
Julien Jerphanion 2025-01-06 17:23:42 +01:00 committed by GitHub
parent d1786964f9
commit bb132c9bff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 37 additions and 0 deletions

View File

@ -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)
{

View File

@ -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");