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

fix: Honour CONDA_ENVS_PATH again #3725

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading