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: Adapt root prefix' precedence for envs_dirs #3813

Merged
merged 7 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion libmamba/include/mamba/api/configuration_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ namespace mamba
{
static std::vector<std::string> default_value(const std::vector<T>& init)
{
return std::vector<std::string>(init.size(), "default");
return std::vector<std::string>(std::max<size_t>(1, init.size()), "default");
};

static void merge(
Expand Down
2 changes: 1 addition & 1 deletion libmamba/src/core/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ namespace mamba
prefix_params.root_prefix = detail::get_root_prefix();
prefix_params.conda_prefix = prefix_params.root_prefix;

envs_dirs = { prefix_params.root_prefix / "envs" };
envs_dirs = {};
pkgs_dirs = { prefix_params.root_prefix / "pkgs",
fs::u8path("~") / ".mamba" / "pkgs"
#ifdef _WIN32
Expand Down
38 changes: 38 additions & 0 deletions micromamba/tests/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ def test_env_logging_overhead_regression(tmp_home, tmp_root_prefix, tmp_path):
"similar_non_canonical,non_canonical_position",
((False, None), (True, "append"), (True, "prepend")),
)
@pytest.mark.parametrize("root_prefix_env_exists", (False, True))
def test_target_prefix(
tmp_home,
tmp_root_prefix,
Expand All @@ -266,6 +267,7 @@ def test_target_prefix(
current_target_prefix_fallback,
similar_non_canonical,
non_canonical_position,
root_prefix_env_exists,
):
cmd = []

Expand All @@ -277,6 +279,9 @@ def test_target_prefix(
else:
root_prefix = Path(os.environ["MAMBA_ROOT_PREFIX"])

if root_prefix_env_exists:
os.mkdir(Path(os.environ["MAMBA_ROOT_PREFIX"]) / "envs")

env_prefix = tmp_path / "myenv"

if target_is_root:
Expand Down Expand Up @@ -661,6 +666,39 @@ def test_create_envs_dirs(tmp_root_prefix: Path, tmp_path: Path):
assert (tmp_path / env_name / "conda-meta" / "history").exists()


@pytest.mark.parametrize("cli_root_prefix", (False, True))
@pytest.mark.parametrize("user_envs_dirs", (False, True))
def test_root_prefix_precedence(monkeypatch, tmp_path, user_envs_dirs, cli_root_prefix):
"""Test for root prefix precedence"""

envroot = tmp_path / "envroot"
cliroot = tmp_path / "cliroot"
userenv = tmp_path / "userenv" / "envs"

map(lambda p: os.makedirs(p), (envroot, cliroot, userenv))

monkeypatch.setenv("MAMBA_ROOT_PREFIX", str(envroot))
cmd = ["mamba", "create", "-n", "foo", "--print-config-only", "--debug"]

if cli_root_prefix:
cmd += ["-r", cliroot]

if user_envs_dirs:
monkeypatch.setenv("CONDA_ENVS_DIRS", str(userenv))

res = helpers.create(*cmd)
envs_dirs = res["envs_dirs"]

if user_envs_dirs:
assert envs_dirs[0] == str(userenv)
envs_dirs = envs_dirs[1:]

if cli_root_prefix:
assert envs_dirs[0] == str(cliroot / "envs")
else:
assert envs_dirs[0] == str(envroot / "envs")


@pytest.mark.skipif(
helpers.dry_run_tests is helpers.DryRun.ULTRA_DRY,
reason="Running only ultra-dry tests",
Expand Down
Loading