mirror of https://github.com/mamba-org/mamba.git
fix: Prohibit conda envs path and conda envs dirs (#3854)
This commit is contained in:
parent
3627ae0177
commit
b7ea5cf4c0
|
@ -1007,15 +1007,21 @@ namespace mamba
|
|||
{
|
||||
// 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)
|
||||
{
|
||||
if (util::get_env("CONDA_ENVS_DIRS"))
|
||||
{
|
||||
const auto message = "The `CONDA_ENVS_DIRS` and `CONDA_ENVS_PATH` environment variables are both set, but only one must be declared. We recommend setting `CONDA_ENVS_DIRS` only. Aborting.";
|
||||
throw mamba_error(message, mamba_error_code::incorrect_usage);
|
||||
}
|
||||
|
||||
auto paths_separator = util::pathsep();
|
||||
|
||||
auto paths = util::split(conda_envs_path.value(), paths_separator);
|
||||
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));
|
||||
}
|
||||
|
||||
dirs.reserve(dirs.size() + paths.size());
|
||||
dirs.insert(dirs.begin(), paths.rbegin(), paths.rend());
|
||||
}
|
||||
|
||||
// Check that the values exist as directories
|
||||
|
@ -1031,7 +1037,7 @@ namespace mamba
|
|||
|
||||
// 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";
|
||||
const 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);
|
||||
|
|
|
@ -663,6 +663,20 @@ def test_create_empty(tmp_home, tmp_root_prefix, tmp_path, prefix_selector, crea
|
|||
assert (effective_prefix / "conda-meta" / "history").exists()
|
||||
|
||||
|
||||
def test_create_conda_envs_dirs_and_path(tmp_root_prefix, monkeypatch):
|
||||
"""Abort when CONDA_ENVS_PATH and CONDA_ENVS_DIRS are both set"""
|
||||
monkeypatch.setenv("CONDA_ENVS_DIRS", f"{tmp_root_prefix / 'env1'}")
|
||||
monkeypatch.setenv("CONDA_ENVS_PATH", f"{tmp_root_prefix / 'env2'}")
|
||||
with pytest.raises(subprocess.CalledProcessError) as info:
|
||||
helpers.create("-n", "test", "--offline", "--no-rc", no_dry_run=True)
|
||||
|
||||
msg = info.value.stderr.decode()
|
||||
assert (
|
||||
"The `CONDA_ENVS_DIRS` and `CONDA_ENVS_PATH` environment variables are both set, but only one must be declared."
|
||||
in msg
|
||||
)
|
||||
|
||||
|
||||
def test_create_envs_dirs(tmp_root_prefix: Path, tmp_path: Path, monkeypatch):
|
||||
"""Create an environment when the first env dir is not writable."""
|
||||
|
||||
|
|
Loading…
Reference in New Issue