Skip to content

Commit 47ea95a

Browse files
authored
Merge pull request #1128 from minrk/micromamba-usr-local
put micromamba in /usr/local/bin and use mamba for installs
2 parents 8c21b96 + 42f83f0 commit 47ea95a

File tree

5 files changed

+29
-28
lines changed

5 files changed

+29
-28
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", "/tmp/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-
/tmp/bin/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: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ URL="https://anaconda.org/conda-forge/micromamba/${MAMBA_VERSION}/download/linux
1515
unset HOME
1616
mkdir -p ${CONDA_DIR}
1717

18-
time wget -qO- ${URL} | tar -xvj bin/micromamba
19-
chmod 0755 /tmp/bin/micromamba
18+
export MICROMAMBA_EXE="/usr/local/bin/micromamba"
2019

21-
export MAMBA_ROOT_PREFIX=${CONDA_DIR}
22-
export MAMBA_EXE="/tmp/bin/micromamba"
20+
time wget -qO- ${URL} | tar -xvj bin/micromamba
21+
mv bin/micromamba "$MICROMAMBA_EXE"
22+
chmod 0755 "$MICROMAMBA_EXE"
2323

24-
eval "$(/tmp/bin/micromamba shell hook -p ${CONDA_DIR} -s posix)"
24+
eval "$(${MICROMAMBA_EXE} shell hook -p ${CONDA_DIR} -s posix)"
2525

2626
micromamba activate
2727

@@ -43,7 +43,7 @@ echo "installing notebook env:"
4343
cat "${NB_ENVIRONMENT_FILE}"
4444

4545

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

4848
if [[ ! -z "${NB_REQUIREMENTS_FILE:-}" ]]; then
4949
echo "installing pip requirements"
@@ -60,7 +60,7 @@ if [[ ! -z "${KERNEL_ENVIRONMENT_FILE:-}" ]]; then
6060
# install kernel env and register kernelspec
6161
echo "installing kernel env:"
6262
cat "${KERNEL_ENVIRONMENT_FILE}"
63-
time micromamba create -p ${KERNEL_PYTHON_PREFIX} -f "${KERNEL_ENVIRONMENT_FILE}"
63+
time ${MAMBA_EXE} create -p ${KERNEL_PYTHON_PREFIX} --file "${KERNEL_ENVIRONMENT_FILE}"
6464

6565
if [[ ! -z "${KERNEL_REQUIREMENTS_FILE:-}" ]]; then
6666
echo "installing pip requirements for kernel"
@@ -70,18 +70,18 @@ if [[ ! -z "${KERNEL_ENVIRONMENT_FILE:-}" ]]; then
7070

7171
${KERNEL_PYTHON_PREFIX}/bin/ipython kernel install --prefix "${NB_PYTHON_PREFIX}"
7272
echo '' > ${KERNEL_PYTHON_PREFIX}/conda-meta/history
73-
micromamba list -p ${KERNEL_PYTHON_PREFIX}
73+
${MAMBA_EXE} list -p ${KERNEL_PYTHON_PREFIX}
7474
fi
7575

7676
# Clean things out!
77-
time micromamba clean --all -y
77+
time ${MAMBA_EXE} clean --all -f -y
7878

7979
# Remove the pip cache created as part of installing micromamba
8080
rm -rf /root/.cache
8181

8282
chown -R $NB_USER:$NB_USER ${CONDA_DIR}
8383

84-
micromamba list -p ${NB_PYTHON_PREFIX}
84+
${MAMBA_EXE} list -p ${NB_PYTHON_PREFIX}
8585

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

tests/conda/binder-dir/verify

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ from subprocess import check_output
44

55
assert sys.version_info[:2] == (3, 5), sys.version
66

7-
out = check_output(["/tmp/bin/micromamba", "--version"]).decode("utf8").strip()
7+
out = check_output(["micromamba", "--version"]).decode("utf8").strip()
88
assert (
99
out
1010
== """micromamba: 0.19.1

tests/conda/simple-py2/verify

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,13 @@ assert sorted(specs) == ["python2", "python3"], specs.keys()
1414
import json
1515
from subprocess import check_output
1616

17-
envs = json.loads(
18-
check_output(["/tmp/bin/micromamba", "env", "list", "--json"]).decode("utf8")
19-
)
17+
envs = json.loads(check_output(["micromamba", "env", "list", "--json"]).decode("utf8"))
2018
assert envs == {
2119
"envs": ["/srv/conda", "/srv/conda/envs/kernel", "/srv/conda/envs/notebook"]
2220
}, envs
2321

2422
pkgs = json.loads(
25-
check_output(["/tmp/bin/micromamba", "list", "-n", "kernel", "--json"]).decode(
26-
"utf8"
27-
)
23+
check_output(["micromamba", "list", "-n", "kernel", "--json"]).decode("utf8")
2824
)
2925
pkg_names = [pkg["name"] for pkg in pkgs]
3026
assert "ipykernel" in pkg_names, pkg_names

0 commit comments

Comments
 (0)