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 shell init for mamba 2 #914

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
21 changes: 16 additions & 5 deletions constructor/header.sh
Original file line number Diff line number Diff line change
Expand Up @@ -671,11 +671,22 @@ if [ "$BATCH" = "0" ]; then
*) "$PREFIX/bin/python" -m conda init ;;
esac
if [ -f "$PREFIX/bin/mamba" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

Seeing this code now, I think it might result into double initialization, right? Once with conda, once with mamba. Are those compatible or should they be exclusive?

Copy link
Author

Choose a reason for hiding this comment

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

I think conda's initialization is overridden by mamba's; so it works, but it might not be totally sane. I guess we can keep the same behavior when 1.x is used unchanged, and see potential adaptations for 2.x.

What do you think? Is there a way to test that this works with both versions?

Copy link
Contributor

Choose a reason for hiding this comment

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

We'll need to add cases for it in the examples/ directory. Maybe you can repurpose the Miniforge example (which might need to get synced up with current Miniforge scripts anyway), and then parametrize with some environment variables as we are doing in some other tests. Check for os.environ in the construct.yaml templates and also monkeypatch.setenv calls in tests/test_examples.py.

case $SHELL in
# We call the module directly to avoid issues with spaces in shebang
*zsh) "$PREFIX/bin/python" -m mamba.mamba init zsh ;;
*) "$PREFIX/bin/python" -m mamba.mamba init ;;
esac
# If the version of mamba is <2.0.0, we preferably use the `mamba` python module
# to perform the initialization.
#
# Otherwise (i.e. as of 2.0.0), we use the `mamba shell init` command
if [ "$("$PREFIX/bin/mamba" --version | cut -d' ' -f2 | cut -d'.' -f1)" -lt 2 ]; then
case $SHELL in
# We call the module directly to avoid issues with spaces in shebang
*zsh) "$PREFIX/bin/python" -m mamba.mamba init zsh ;;
*) "$PREFIX/bin/python" -m mamba.mamba init ;;
esac
else
case $SHELL in
*zsh) "$PREFIX/bin/mamba" shell init --shell zsh ;;
*) "$PREFIX/bin/mamba" shell init ;;
esac
fi
fi
fi
{%- endif %}
Expand Down
19 changes: 19 additions & 0 deletions news/914-shell-init-on-mamba-2
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Enhancements

* <news item>

### Bug fixes

* Add support of mamba v2 shell initialization. (#914)

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>
Loading