Freeze enviornment with conda-lock
approximately one million times faster than running a full install
installation time should be faster, too, as there is no solve
MODIFY
repo2docker/buildpacks/conda/environment.yml
repo2docker/buildpacks/conda/environment.yml
+channels:
+ - conda-forge
dependencies:
- python=3.7
- ipywidgets==7.6.3

MODIFY
repo2docker/buildpacks/conda/freeze.py
repo2docker/buildpacks/conda/freeze.py
"""
Freeze the conda environment.yml
-It runs the freeze in a continuumio/miniconda3 image to ensure portability
+Using conda-lock
Usage:
@@ -19,12 +19,6 @@ import sys
from ruamel.yaml import YAML
-DOCKER_IMAGE = "condaforge/mambaforge:4.9.2-5"
-# set mamba and/or conda versions
-# if needed to differ from what's in the image
-MAMBA_VERSION = ""
-CONDA_VERSION = ""
-
HERE = pathlib.Path(os.path.dirname(os.path.abspath(__file__)))
ENV_FILE = HERE / "environment.yml"
@@ -36,13 +30,12 @@ FROZEN_FILE_T = os.path.splitext(ENV_FILE_T)[0] + ".frozen.yml"
yaml = YAML(typ="rt")
-def freeze(env_file, frozen_file):
+def freeze(env_file, frozen_file, platform="linux-64"):
"""Freeze a conda environment.yml
- By running in docker:
+ By running
- mamba env create
- mamba env export
+ conda-lock --mamba --platform=linux-64 -f environment.yml
Result will be stored in frozen_file
"""
@@ -58,43 +51,32 @@ def freeze(env_file, frozen_file):
return
print(f"Freezing {env_file} -> {frozen_file}")
+ # FIXME: conda-lock 0.8 requires {platform} in template
+ # https://github.com/conda-incubator/conda-lock/pull/78
+ frozen_template = str(frozen_dest) + ".{platform}"
+ frozen_tempfile = pathlib.Path(frozen_template.format(platform=platform))
+
+ check_call(
+ [
+ "conda-lock",
+ # FIXME: adopt micromamba after ordering is fixed
+ # https://github.com/conda-incubator/conda-lock/issues/79
+ "--mamba",
+ f"--platform={platform}",
+ f"--filename-template={frozen_template}",
+ f"--file={env_file}",
+ ]
+ )
+
with frozen_dest.open("w") as f:
f.write(
f"# AUTO GENERATED FROM {env_file.relative_to(HERE)}, DO NOT MANUALLY MODIFY\n"
)
f.write(f"# Frozen on {datetime.utcnow():%Y-%m-%d %H:%M:%S UTC}\n")
+ with frozen_tempfile.open() as temp:
+ f.write(temp.read())
- check_call(
- [
- "docker",
- "run",
- "--rm",
- "-v" f"{HERE}:/r2d",
- "-it",
- DOCKER_IMAGE,
- "sh",
- "-c",
- "; ".join(
- [
- "set -ex",
- "conda config --set channel_priority strict",
- "conda config --add channels conda-forge",
- f"mamba install -yq -S mamba={MAMBA_VERSION}"
- if MAMBA_VERSION
- else "true",
- f"mamba install -yq -S conda={CONDA_VERSION}"
- if CONDA_VERSION
- else "true",
- "conda config --system --set auto_update_conda false",
- f"mamba env create -v -f /r2d/{env_file.relative_to(HERE)} -n r2d",
- # add conda-forge broken channel as lowest priority in case
- # any of our frozen packages are marked as broken after freezing
- "conda config --append channels conda-forge/label/broken",
- f"mamba env export -n r2d >> /r2d/{frozen_file.relative_to(HERE)}",
- ]
- ),
- ]
- )
+ os.remove(frozen_tempfile)
def set_python(py_env_file, py):

Freeze enviornment with conda-lock

approximately one million times faster than running a full install

installation time should be faster, too, as there is no solve