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

No profile.d fallback in rc files #2649

Merged
merged 2 commits into from
Jul 6, 2023

Conversation

AntoinePrv
Copy link
Member

Continuation to #2631.

@jonashaag @pavelzw does the error handling seem good to you, or will it be incompatible with #2577?

For readability, current output on my system is:

# >>> mamba initialize >>>
# !! Contents within this block are managed by 'mamba init' !!
export MAMBA_EXE='/home/antoine/workspace/github.com/mamba-org/mamba/build/cmake/micromamba/micromamba';
export MAMBA_ROOT_PREFIX='/home/antoine/.local/share/mamba';
__mamba_setup="$("$MAMBA_EXE" shell hook --shell bash --root-prefix "$MAMBA_ROOT_PREFIX" 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__mamba_setup"
else
    alias micromamba='echo "Failed to initialize shell for micromamba.\nTry running micromamba shell reinit." 1>&2; "$MAMBA_EXE" "$@"'
fi
unset __mamba_setup
# <<< mamba initialize <<<

@jonashaag
Copy link
Collaborator

Does this even work? If you set micromamba to this dummy function, how are you supposed to shell reinit?

@AntoinePrv
Copy link
Member Author

AntoinePrv commented Jul 3, 2023

It would because the message is added at the top, then the alias calls into $MAMBA_EXE.
But you make me realize that perhaps we could simply fallback to alias micromamba="$MAMBA_EXE", since activating with the binary will give the message:

'micromamba' is running as a subprocess and can't modify the parent shell.
Thus you must initialize your shell before using activate and deactivate.

To initialize the current  shell, run:
    $ eval "$(micromamba shell hook --shell )"
and then activate or deactivate with:
    $ micromamba activate
To automatically initialize all future () shells, run:
    $ micromamba shell init --shell  --root-prefix=~/micromamba

Supported shells are {bash, zsh, csh, xonsh, cmd.exe, powershell, fish}.

@jonashaag
Copy link
Collaborator

jonashaag commented Jul 3, 2023

Oh sorry I didn't see the call into $MAMBA_EXE 🙈

Somewhat relatedly, I would actually prefer to see error messages. Maybe we can remove the 2>/dev/null above?

@AntoinePrv
Copy link
Member Author

AntoinePrv commented Jul 3, 2023

Somewhat relatedly, I would actually prefer to see error messages. Maybe we can remove the 2>/dev/null above?

That's a good idea! I think we should delay it unit the user calls micromamba and not when the rc file is sourced.
Alteratively we could instruct user to call "$MAMBA_EXE" shell hook --shell bash --root-prefix "$MAMBA_ROOT_PREFIX" in the 'micromamba' is running as a subprocess and can't modify the parent shell. message.

@AntoinePrv AntoinePrv self-assigned this Jul 5, 2023
@AntoinePrv AntoinePrv requested a review from Hind-M July 5, 2023 16:08
@AntoinePrv
Copy link
Member Author

I propose:

# >>> mamba initialize >>>
# !! Contents within this block are managed by 'mamba init' !!
export MAMBA_EXE='/home/antoine/workspace/github.com/mamba-org/mamba/build/cmake/micromamba/micromamba';
export MAMBA_ROOT_PREFIX='/home/antoine/workspace/github.com/mamba-org/mamba/foo';
__mamba_setup="$("$MAMBA_EXE" shell hook --shell bash --root-prefix "$MAMBA_ROOT_PREFIX" 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__mamba_setup"
else
    alias micromamba="$MAMBA_EXE"  # Fallback on help from mamba activate
fi
unset __mamba_setup
# <<< mamba initialize <<<

And the message

'micromamba' is running as a subprocess and can't modify the parent shell.
Thus you must initialize your shell before using activate and deactivate.

To initialize the current  shell, run:
    $ eval "$(micromamba shell hook --shell )"
and then activate or deactivate with:
    $ micromamba activate
To automatically initialize all future (zsh) shells, run:
    $ micromamba shell init --shell zsh --root-prefix=~/micromamba
If your shell was already initialized, reinitialize your shell with:
    $ micromamba shell reinit --shell
Otherwise, this may be an issue. In the meantime you can run commands. See:
    $ micromamba run --help

Supported shells are {bash, zsh, csh, xonsh, cmd.exe, powershell, fish}.

@JohanMabille JohanMabille merged commit 5b931ed into mamba-org:main Jul 6, 2023
20 checks passed
@AntoinePrv AntoinePrv deleted the fix-profile-d branch July 6, 2023 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants