Skip to content

Commit 42f83f0

Browse files
committed
use mamba for installs once available
MAMBA_EXE is mamba itself, not micromamba use variable everywhere, so switching fully to micromamba can happen in once place, assuming they are fully compatible (they _almost_ are, except for `env update` vs `install` in a couple places)
1 parent 8422002 commit 42f83f0

File tree

3 files changed

+25
-21
lines changed

3 files changed

+25
-21
lines changed

repo2docker/buildpacks/conda/__init__.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ def get_build_env(self):
5656
("NPM_CONFIG_GLOBALCONFIG", "${NPM_DIR}/npmrc"),
5757
("NB_ENVIRONMENT_FILE", self._nb_environment_file),
5858
("MAMBA_ROOT_PREFIX", "${CONDA_DIR}"),
59-
("MAMBA_EXE", "/usr/local/bin/micromamba"),
59+
# this exe should be used for installs after bootstrap with micromamba
60+
# switch this to /usr/local/bin/micromamba to use it for all installs
61+
("MAMBA_EXE", "${CONDA_DIR}/bin/mamba"),
6062
]
6163
if self._nb_requirements_file:
6264
env.append(("NB_REQUIREMENTS_FILE", self._nb_requirements_file))
@@ -334,13 +336,15 @@ def get_env_scripts(self):
334336
environment_yml = self.binder_path("environment.yml")
335337
env_prefix = "${KERNEL_PYTHON_PREFIX}" if self.py2 else "${NB_PYTHON_PREFIX}"
336338
if os.path.exists(environment_yml):
339+
# TODO: when using micromamba, we call $MAMBA_EXE install -p ...
340+
# whereas mamba/conda need `env update -p ...` when it's an env.yaml file
337341
scripts.append(
338342
(
339343
"${NB_USER}",
340344
r"""
341345
TIMEFORMAT='time: %3R' \
342-
bash -c 'time ${{MAMBA_EXE}} install -p {0} -f "{1}" && \
343-
time ${{MAMBA_EXE}} clean --all -y && \
346+
bash -c 'time ${{MAMBA_EXE}} env update -p {0} --file "{1}" && \
347+
time ${{MAMBA_EXE}} clean --all -f -y && \
344348
${{MAMBA_EXE}} list -p {0} \
345349
'
346350
""".format(
@@ -359,7 +363,7 @@ def get_env_scripts(self):
359363
"${NB_USER}",
360364
r"""
361365
${{MAMBA_EXE}} install -p {0} r-base{1} r-irkernel=1.2 r-devtools -y && \
362-
${{MAMBA_EXE}} clean --all -y && \
366+
${{MAMBA_EXE}} clean --all -f -y && \
363367
${{MAMBA_EXE}} list -p {0}
364368
""".format(
365369
env_prefix, r_pin
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# enable conda and activate the notebook environment
2-
micromamba shell init -s bash -p ${CONDA_DIR}
3-
export MAMBA_ROOT_PREFIX="/srv/conda"
4-
CONDA_PROFILE="${CONDA_DIR}/etc/profile.d/mamba.sh"
5-
test -f $CONDA_PROFILE && . $CONDA_PROFILE
2+
eval $(micromamba shell hook -s posix -p ${CONDA_DIR})
3+
for name in conda mamba; do
4+
CONDA_PROFILE="${CONDA_DIR}/etc/profile.d/${name}.sh"
5+
test -f $CONDA_PROFILE && . $CONDA_PROFILE
6+
done
67
if [[ "${KERNEL_PYTHON_PREFIX}" != "${NB_PYTHON_PREFIX}" ]]; then
78
# if the kernel is a separate env, stack them
89
# so both are on PATH, notebook first
9-
micromamba activate ${KERNEL_PYTHON_PREFIX}
10-
micromamba activate --stack ${NB_PYTHON_PREFIX}
10+
mamba activate ${KERNEL_PYTHON_PREFIX}
11+
mamba activate --stack ${NB_PYTHON_PREFIX}
1112

1213
# even though it's second on $PATH
1314
# make sure CONDA_DEFAULT_ENV is the *kernel* env
@@ -16,5 +17,5 @@ if [[ "${KERNEL_PYTHON_PREFIX}" != "${NB_PYTHON_PREFIX}" ]]; then
1617
# which only contains UI when the two are different
1718
export CONDA_DEFAULT_ENV="${KERNEL_PYTHON_PREFIX}"
1819
else
19-
micromamba activate ${NB_PYTHON_PREFIX}
20+
mamba activate ${NB_PYTHON_PREFIX}
2021
fi

repo2docker/buildpacks/conda/install-base-env.bash

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@ URL="https://anaconda.org/conda-forge/micromamba/${MAMBA_VERSION}/download/linux
1515
unset HOME
1616
mkdir -p ${CONDA_DIR}
1717

18-
export MAMBA_ROOT_PREFIX=${CONDA_DIR}
19-
export MAMBA_EXE="/usr/local/bin/micromamba"
18+
export MICROMAMBA_EXE="/usr/local/bin/micromamba"
2019

2120
time wget -qO- ${URL} | tar -xvj bin/micromamba
22-
mv bin/micromamba "$MAMBA_EXE"
23-
chmod 0755 "$MAMBA_EXE"
21+
mv bin/micromamba "$MICROMAMBA_EXE"
22+
chmod 0755 "$MICROMAMBA_EXE"
2423

25-
eval "$(${MAMBA_EXE} shell hook -p ${CONDA_DIR} -s posix)"
24+
eval "$(${MICROMAMBA_EXE} shell hook -p ${CONDA_DIR} -s posix)"
2625

2726
micromamba activate
2827

@@ -44,7 +43,7 @@ echo "installing notebook env:"
4443
cat "${NB_ENVIRONMENT_FILE}"
4544

4645

47-
time micromamba create -p ${NB_PYTHON_PREFIX} -f "${NB_ENVIRONMENT_FILE}"
46+
time ${MAMBA_EXE} create -p ${NB_PYTHON_PREFIX} --file "${NB_ENVIRONMENT_FILE}"
4847

4948
if [[ ! -z "${NB_REQUIREMENTS_FILE:-}" ]]; then
5049
echo "installing pip requirements"
@@ -61,7 +60,7 @@ if [[ ! -z "${KERNEL_ENVIRONMENT_FILE:-}" ]]; then
6160
# install kernel env and register kernelspec
6261
echo "installing kernel env:"
6362
cat "${KERNEL_ENVIRONMENT_FILE}"
64-
time micromamba create -p ${KERNEL_PYTHON_PREFIX} -f "${KERNEL_ENVIRONMENT_FILE}"
63+
time ${MAMBA_EXE} create -p ${KERNEL_PYTHON_PREFIX} --file "${KERNEL_ENVIRONMENT_FILE}"
6564

6665
if [[ ! -z "${KERNEL_REQUIREMENTS_FILE:-}" ]]; then
6766
echo "installing pip requirements for kernel"
@@ -71,18 +70,18 @@ if [[ ! -z "${KERNEL_ENVIRONMENT_FILE:-}" ]]; then
7170

7271
${KERNEL_PYTHON_PREFIX}/bin/ipython kernel install --prefix "${NB_PYTHON_PREFIX}"
7372
echo '' > ${KERNEL_PYTHON_PREFIX}/conda-meta/history
74-
micromamba list -p ${KERNEL_PYTHON_PREFIX}
73+
${MAMBA_EXE} list -p ${KERNEL_PYTHON_PREFIX}
7574
fi
7675

7776
# Clean things out!
78-
time micromamba clean --all -y
77+
time ${MAMBA_EXE} clean --all -f -y
7978

8079
# Remove the pip cache created as part of installing micromamba
8180
rm -rf /root/.cache
8281

8382
chown -R $NB_USER:$NB_USER ${CONDA_DIR}
8483

85-
micromamba list -p ${NB_PYTHON_PREFIX}
84+
${MAMBA_EXE} list -p ${NB_PYTHON_PREFIX}
8685

8786
# Set NPM config
8887
${NB_PYTHON_PREFIX}/bin/npm config --global set prefix ${NPM_DIR}

0 commit comments

Comments
 (0)