lockfiles need to be installed with `conda create` not `conda env create`

use different .lock filename extension, following conda-lock precedent

Could also follow .txt in conda docs!

conda env create -p prefix -f lock.txt *should* work,
but fails with errors about name being required,
but also fails if name is given due to conflict with `-p`
pull/1024/head
Min RK 2021-03-03 15:35:29 +01:00
rodzic d7c26b7a79
commit 789a3a23c3
9 zmienionych plików z 51 dodań i 21 usunięć

Wyświetl plik

@ -23,6 +23,14 @@ class CondaBuildPack(BaseImage):
"""
# The kernel environment file, if any.
# As an absolute path within the container.
_kernel_environment_file = ""
# The notebook server environment file, if any.
# As an absolute path within the container.
_nb_environment_file = ""
def get_build_env(self):
"""Return environment variables to be set.
@ -33,9 +41,15 @@ class CondaBuildPack(BaseImage):
env = super().get_build_env() + [
("CONDA_DIR", "${APP_BASE}/conda"),
("NB_PYTHON_PREFIX", "${CONDA_DIR}/envs/notebook"),
("NB_ENVIRONMENT_FILE", self._nb_environment_file),
]
if self.py2:
env.append(("KERNEL_PYTHON_PREFIX", "${CONDA_DIR}/envs/kernel"))
env.extend(
[
("KERNEL_PYTHON_PREFIX", "${CONDA_DIR}/envs/kernel"),
("KERNEL_ENVIRONMENT_FILE", self._kernel_environment_file),
]
)
else:
env.append(("KERNEL_PYTHON_PREFIX", "${NB_PYTHON_PREFIX}"))
return env
@ -81,7 +95,7 @@ class CondaBuildPack(BaseImage):
r"""
TIMEFORMAT='time: %3R' \
bash -c 'time /tmp/install-miniforge.bash' && \
rm /tmp/install-miniforge.bash /tmp/environment.yml
rm /tmp/install-miniforge.bash ${NB_ENVIRONMENT_FILE}
""",
)
]
@ -114,20 +128,25 @@ class CondaBuildPack(BaseImage):
# major Python versions during upgrade.
# If no version is specified or no matching X.Y version is found,
# the default base environment is used.
frozen_name = "environment.frozen.yml"
frozen_name = "environment.lock"
if py_version:
if self.py2:
# python 2 goes in a different env
files[
"conda/environment.py-2.7.frozen.yml"
] = "/tmp/kernel-environment.yml"
"conda/environment.py-2.7.lock"
] = self._kernel_environment_file = "/tmp/kernel-environment.lock"
else:
py_frozen_name = "environment.py-{py}.frozen.yml".format(py=py_version)
if os.path.exists(os.path.join(HERE, py_frozen_name)):
frozen_name = py_frozen_name
else:
self.log.warning("No frozen env: %s", py_frozen_name)
files["conda/" + frozen_name] = "/tmp/environment.yml"
for ext in [".lock", ".frozen.yml"]:
py_frozen_name = f"environment.py-{py_version}{ext}"
if os.path.exists(os.path.join(HERE, py_frozen_name)):
frozen_name = py_frozen_name
break
if not frozen_name:
self.log.warning(f"No frozen env for {py_version}")
_, frozen_ext = os.path.splitext(frozen_name)
files[
"conda/" + frozen_name
] = self._nb_environment_file = f"/tmp/environment{frozen_ext}"
files.update(super().get_build_script_files())
return files

Wyświetl plik

@ -22,18 +22,17 @@ from ruamel.yaml import YAML
HERE = pathlib.Path(os.path.dirname(os.path.abspath(__file__)))
ENV_FILE = HERE / "environment.yml"
FROZEN_FILE = os.path.splitext(ENV_FILE)[0] + ".frozen.yml"
FROZEN_FILE = os.path.splitext(ENV_FILE)[0] + ".lock"
ENV_FILE_T = HERE / "environment.py-{py}.yml"
FROZEN_FILE_T = os.path.splitext(ENV_FILE_T)[0] + ".frozen.yml"
yaml = YAML(typ="rt")
def freeze(env_file, frozen_file, platform="linux-64"):
"""Freeze a conda environment.yml
"""Freeze a conda environment
By running
By running:
conda-lock --mamba --platform=linux-64 -f environment.yml
@ -113,7 +112,7 @@ if __name__ == "__main__":
for py in pys:
env_file = pathlib.Path(str(ENV_FILE_T).format(py=py))
set_python(env_file, py)
frozen_file = pathlib.Path(os.path.splitext(env_file)[0] + ".frozen.yml")
frozen_file = pathlib.Path(os.path.splitext(env_file)[0] + ".lock")
freeze(env_file, frozen_file)
if py == default_py:
shutil.copy(frozen_file, FROZEN_FILE)

Wyświetl plik

@ -45,8 +45,15 @@ conda config --system --set channel_priority "flexible"
time mamba install -y mamba==${MAMBA_VERSION}
echo "installing notebook env:"
cat /tmp/environment.yml
time mamba create --prefix ${NB_PYTHON_PREFIX} --file /tmp/environment.yml
cat "${NB_ENVIRONMENT_FILE}"
if [[ "${NB_ENVIRONMENT_FILE: -5}" == ".lock" ]]; then
create="mamba create"
else
create="mamba env create"
fi
time $create -p ${NB_PYTHON_PREFIX} --file "${NB_ENVIRONMENT_FILE}"
# empty conda history file,
# which seems to result in some effective pinning of packages in the initial env,
@ -54,12 +61,17 @@ time mamba create --prefix ${NB_PYTHON_PREFIX} --file /tmp/environment.yml
# this file must not be *removed*, however
echo '' > ${NB_PYTHON_PREFIX}/conda-meta/history
if [[ -f /tmp/kernel-environment.yml ]]; then
if [[ ! -z "${KERNEL_ENVIRONMENT_FILE:-}" && -f "${KERNEL_ENVIRONMENT_FILE}" ]]; then
# install kernel env and register kernelspec
echo "installing kernel env:"
cat /tmp/kernel-environment.yml
cat "${KERNEL_ENVIRONMENT_FILE}"
if [[ "${KERNEL_ENVIRONMENT_FILE: -5}" == ".lock" ]]; then
create="mamba create"
else
create="mamba env create"
fi
time mamba create --prefix ${KERNEL_PYTHON_PREFIX} --file /tmp/kernel-environment.yml
time $create -p ${KERNEL_PYTHON_PREFIX} --file "${KERNEL_ENVIRONMENT_FILE}"
${KERNEL_PYTHON_PREFIX}/bin/ipython kernel install --prefix "${NB_PYTHON_PREFIX}"
echo '' > ${KERNEL_PYTHON_PREFIX}/conda-meta/history
mamba list -p ${KERNEL_PYTHON_PREFIX}