24 Generates the code to set up a conda/mamba/micromamba environment.
26 \note Only micromamba is officially supported.
29 env_name = os.environ[
'CONDA_DEFAULT_ENV']
32 if 'MAMBA_EXE' in os.environ
and 'MAMBA_ROOT_PREFIX' in os.environ:
35 # Make sure {mamba_exe_name} is set up
36 export MAMBA_EXE='{mamba_exe}';
37 export MAMBA_ROOT_PREFIX='{mamba_root}';
38 __mamba_setup="$("$MAMBA_EXE" shell hook --shell bash --root-prefix "$MAMBA_ROOT_PREFIX" 2> /dev/null)"
42 alias {mamba_exe_name}="$MAMBA_EXE" # Fallback on help from mamba activate
46 # Enable the environment
47 {mamba_exe_name} activate '{env_name}'
49 mamba_exe = os.environ[
'MAMBA_EXE']
50 mamba_root = os.environ[
'MAMBA_ROOT_PREFIX']
51 mamba_exe_name =
'micromamba' if mamba_exe.endswith(
'micromamba')
else 'mamba'
52 return template.format(mamba_exe=mamba_exe,
53 mamba_root=mamba_root,
54 mamba_exe_name=mamba_exe_name,
56 elif 'CONDA_EXE' in os.environ:
58 # Make sure conda is set up
59 __conda_setup="$('{conda_exe}' 'shell.bash' 'hook' 2> /dev/null)"
63 if [ -f "{conda_base}/etc/profile.d/conda.sh" ]; then
64 . "{conda_base}/etc/profile.d/conda.sh"
66 export PATH="{conda_base}/bin:$PATH"
71 # Enable the environment
72 conda activate '{env_name}'
75 conda_exe = os.environ[
'CONDA_EXE']
76 conda_root = abspath(join(conda_exe, os.pardir, os.pardir))
77 return template.format(conda_exe=conda_exe,
78 conda_root=conda_root,
81 raise ValueError(
'\x1B[31mUnknown conda-like environment\x1B[0m')