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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

holzman
Copy link

@holzman holzman commented Feb 10, 2025

Adds a new test and fixes #3806. With this PR it now has the desired behavior:

$ mamba create -r /tmp/cliroot --debug -n foo --print-config-only | yq '. | .envs_dirs'
[
  "/tmp/cliroot/envs"
]

$ MAMBA_ROOT_PREFIX=/tmp/envroot mamba create --debug -n foo --print-config-only | yq '. | .envs_dirs'
[
  "/tmp/envroot/envs"
]

$ MAMBA_ROOT_PREFIX=/tmp/envroot mamba create -r /tmp/cliroot --debug -n foo --print-config-only | yq '. | .envs_dirs'
[
  "/tmp/cliroot/envs"
]

$ CONDA_ENVS_DIRS=/tmp/userdirs/envs MAMBA_ROOT_PREFIX=/tmp/envroot mamba create --debug -n foo --print-config-only | yq '. | .envs_dirs'
[
  "/tmp/userdirs/envs",
  "/tmp/envroot/envs"
]

One note - in order for this approach to work, I needed to ensure that the minimum vector size for configuration items was 1 so that --print-config didn't crash. (Alternatively I could change the print-config code to ignore a zero-size vector, but this seemed like a more robust approach).

This adds the case to simulate what happens when
${MAMBA_ROOT_PREFIX}/envs already exists.
@jjerphan jjerphan changed the title Fix root prefix precedence fix: Adapt root prefix' precedence for envs_dirs Feb 11, 2025
@jjerphan jjerphan added the release::bug_fixes For PRs fixing bugs label Feb 11, 2025
Copy link
Member

@jjerphan jjerphan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution, @holzman!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add at least a test based on the outputs that you have given in the description of the PR?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

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

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this required because of #3790?

Suggested change
map(lambda p: os.makedirs(p), (envroot, cliroot, userenv))
map(lambda p: os.makedirs(p, exist_ok=True), (envroot, cliroot, userenv))

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes


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

monkeypatch.setenv("MAMBA_ROOT_PREFIX", str(envroot))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you set it at the really top of this test?

Comment on lines +686 to +687
if user_envs_dirs:
monkeypatch.setenv("CONDA_ENVS_DIRS", str(userenv))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identically, can you set it at the top of the test?

Comment on lines +674 to +676
envroot = tmp_path / "envroot"
cliroot = tmp_path / "cliroot"
userenv = tmp_path / "userenv" / "envs"
Copy link
Member

@jjerphan jjerphan Feb 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you distinguish the prefixes from their envs folders?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I don't quite understand what you're asking.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant to have something like:

Suggested change
envroot = tmp_path / "envroot"
cliroot = tmp_path / "cliroot"
userenv = tmp_path / "userenv" / "envs"
envroot = tmp_path / "envroot"
cliroot = tmp_path / "cliroot"
userenv = tmp_path / "userenv"
env_root_envs = envroot / "envs"
cliroot_envs = cliroot / "envs"
userenv_envs = userenv / "envs

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

res = helpers.create(*cmd)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you check that foo is successfully created and that, depending the test case, foo is created under envroot/envs, cliroot/envs or (after distinguishing prefixes from their envs folder) userenv/envs?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to checking the output from --print-config or in addition to it?

Comment on lines +282 to +284
if root_prefix_env_exists:
os.mkdir(Path(os.environ["MAMBA_ROOT_PREFIX"]) / "envs")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of #3790.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if root_prefix_env_exists:
os.mkdir(Path(os.environ["MAMBA_ROOT_PREFIX"]) / "envs")
# TODO: Remove once https://github.com/mamba-org/mamba/issues/3790 is fixed.
if root_prefix_env_exists:
os.mkdir(Path(os.environ["MAMBA_ROOT_PREFIX"]) / "envs", exist_ok=True)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release::bug_fixes For PRs fixing bugs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MAMBA_ROOT_PREFIX has precedence over -r option
2 participants