mirror of https://github.com/mamba-org/mamba.git
fix: Adapt root prefix' precedence for CONDA_ENVS_PATH (#3852)
This commit is contained in:
parent
b6b1143b1b
commit
902fd1990f
|
@ -1005,24 +1005,16 @@ namespace mamba
|
|||
|
||||
void envs_dirs_hook(const Context& context, std::vector<fs::u8path>& dirs)
|
||||
{
|
||||
// Check that "root_prefix/envs" is already in the dirs,
|
||||
// and append if not - to match `conda`
|
||||
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);
|
||||
}
|
||||
|
||||
// Also add all the directories in the environment variable `CONDA_ENVS_PATH`.
|
||||
// Prepend 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));
|
||||
for (auto it = paths.rbegin(); it != paths.rend(); ++it)
|
||||
{ // prepend conda_envs_path to dirs while maintaining order
|
||||
dirs.insert(dirs.begin(), fs::u8path(*it));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1036,6 +1028,14 @@ namespace mamba
|
|||
throw std::runtime_error("Aborting.");
|
||||
}
|
||||
}
|
||||
|
||||
// Check that "root_prefix/envs" is already in the dirs,
|
||||
// and append if not - to match `conda`
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<fs::u8path> fallback_pkgs_dirs_hook(const Context& context)
|
||||
|
|
|
@ -757,6 +757,7 @@ def test_env_dir_idempotence(tmp_path, tmp_home, tmp_root_prefix):
|
|||
assert Path(condarc_envs_dirs / env_name).exists()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("conda_envs_x", ("CONDA_ENVS_DIRS", "CONDA_ENVS_PATH"))
|
||||
@pytest.mark.parametrize("set_in_conda_envs_dirs", (False, True))
|
||||
@pytest.mark.parametrize("set_in_condarc", (False, True))
|
||||
@pytest.mark.parametrize("cli_root_prefix", (False, True))
|
||||
|
@ -765,6 +766,7 @@ def test_root_prefix_precedence(
|
|||
tmp_path,
|
||||
tmp_home,
|
||||
monkeypatch,
|
||||
conda_envs_x,
|
||||
set_in_condarc,
|
||||
set_in_conda_envs_dirs,
|
||||
cli_root_prefix,
|
||||
|
@ -794,7 +796,7 @@ def test_root_prefix_precedence(
|
|||
env_name = "foo"
|
||||
monkeypatch.setenv("MAMBA_ROOT_PREFIX", str(mamba_root_prefix))
|
||||
if set_in_conda_envs_dirs:
|
||||
monkeypatch.setenv("CONDA_ENVS_DIRS", str(conda_envs_dirs))
|
||||
monkeypatch.setenv(conda_envs_x, str(conda_envs_dirs))
|
||||
|
||||
with open(tmp_home / ".condarc", "w+") as f:
|
||||
if set_in_condarc:
|
||||
|
|
Loading…
Reference in New Issue