23 Generates the code to set up a conda/mamba/micromamba environment.
25 \note Only micromamba is officially supported.
28 env_name = os.environ[
'CONDA_DEFAULT_ENV']
31 if 'MAMBA_EXE' in os.environ
and 'MAMBA_ROOT_PREFIX' in os.environ:
34 # Make sure {mamba_exe_name} is set up
35 export MAMBA_EXE='{mamba_exe}';
36 export MAMBA_ROOT_PREFIX='{mamba_root}';
37 __mamba_setup="$("$MAMBA_EXE" shell hook --shell bash --root-prefix "$MAMBA_ROOT_PREFIX" 2> /dev/null)"
41 alias {mamba_exe_name}="$MAMBA_EXE" # Fallback on help from mamba activate
45 # Enable the environment
46 {mamba_exe_name} activate '{env_name}'
48 mamba_exe = os.environ[
'MAMBA_EXE']
49 mamba_root = os.environ[
'MAMBA_ROOT_PREFIX']
50 mamba_exe_name =
'micromamba' if mamba_exe.endswith(
'micromamba')
else 'mamba'
51 return template.format(mamba_exe=mamba_exe,
52 mamba_root=mamba_root,
53 mamba_exe_name=mamba_exe_name,
55 elif 'CONDA_EXE' in os.environ:
57 # Make sure conda is set up
58 __conda_setup="$('{conda_exe}' 'shell.bash' 'hook' 2> /dev/null)"
62 if [ -f "{conda_base}/etc/profile.d/conda.sh" ]; then
63 . "{conda_base}/etc/profile.d/conda.sh"
65 export PATH="{conda_base}/bin:$PATH"
70 # Enable the environment
71 conda activate '{env_name}'
73 conda_exe = os.environ[
'CONDA_EXE']
74 conda_root = abspath(join(conda_exe, os.pardir, os.pardir))
75 return template.format(conda_exe=conda_exe,
76 conda_root=conda_root,
79 raise ValueError(
'Unknown conda-like environment')