-
Notifications
You must be signed in to change notification settings - Fork 18
/
lock-environment.sh
executable file
·39 lines (31 loc) · 1.12 KB
/
lock-environment.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env bash
# This script will re-generate reproducible lockfiles
# Execution needs to be from inside the `conda` folder
ENV_FILE="environment.yml"
LOCK_ENV='CondaLock'
# Generate CondaLock environment unless present
conda env list | grep ${LOCK_ENV} > /dev/null
# https://github.com/conda-incubator/conda-lock/issues/229
if [[ $? -eq 1 ]]; then
conda create -q -y -n ${LOCK_ENV} -c conda-forge conda-lock=1.0.5 mamba=0.27
fi
# https://github.com/conda/conda/issues/7980#issuecomment-492784093
eval "$(conda shell.bash hook)"
conda activate ${LOCK_ENV}
if [[ ! -s "${ENV_FILE}" ]]; then
>&2 printf " Missing ${ENV_FILE} to generate environments with\n"
>&2 printf " Are you inside the 'conda' folder?\n"
exit 1
fi
# Local environments
## Generate explicit lock files
conda-lock lock --mamba -f ${ENV_FILE}
# BinderHub support
## Generate environment.yml for binder compatibility
printf "Generate environment.yml for BinderHub \n"
conda-lock render -k env
# Remove CondaLock environment when the last command was successful
if [[ $? -eq 0 ]]; then
conda deactivate
conda remove -q -y --name ${LOCK_ENV} --all
fi