This repository has been archived by the owner on Mar 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup-env.sh
95 lines (81 loc) · 2.13 KB
/
setup-env.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash
msg()
{
echo "$@" >&2
}
err()
{
echo "ERR:" "$@" >&2
exit 3
}
vr()
{
echo + "$@" >&2
"$@"
if [ $? -ne 0 ]; then
echo "command $1 terminated with code $?" >&2
exit 2
fi
}
gh_out()
{
local name
name="$1"
shift
echo "::set-output name=$name::$*"
}
set_platform()
{
case "$1" in
osx-*|linux-*|win-*) CONDA_PLATFORM="$1";;
ubuntu) CONDA_PLATFORM=linux-64;;
macos) CONDA_PLATFORM=osx-64;;
windows) CONDA_PLATFORM=win-64;;
*) err "Invalid platform $1";;
esac
echo "::set-output name=conda_platform::$CONDA_PLATFORM"
msg "Running with Conda platform $CONDA_PLATFORM"
}
extras=""
spec_opts=""
env_name="lktest"
mode=lock
while getopts "p:V:e:s:n:" opt; do
case $opt in
n) env_name="$OPTARG";;
p) os_plat="$OPTARG";;
V) spec_opts="$spec_opts -f build-tools/python-$OPTARG-spec.yml";;
e) if [ -z "$extras" ]; then extras="$OPTARG"; else extras="$extras,$OPTARG"; fi;;
s) spec_opts="$spec_opts -f build-tools/$OPTARG-spec.yml";;
\?) err "invalid argument";;
esac
done
if [ -z "$os_plat" ]; then
PLAT=$(uname |tr [A-Z] [a-z])
fi
set_platform "$os_plat"
test -n "$CONDA_PLATFORM" || err "conda platform not set for some reason"
if [ -n "$CONDA" ]; then
msg "activating Conda from $CONDA"
if [ $CONDA_PLATFORM = win-64 ]; then
CONDA_EXE="$CONDA/Scripts/conda.exe"
else
CONDA_EXE="$CONDA/condabin/conda"
fi
eval "$($CONDA_EXE shell.bash hook)"
vr python -V
msg "configuring cache dir"
conda config --add pkgs_dirs $HOME/conda_pkgs_dir
msg "creating bootstrap environment"
vr conda env create -n lkboot -f build-tools/boot-env.yml
msg "activating bootstrap environment"
conda activate lkboot
fi
msg "Preparing Conda environment lockfile"
vr conda-lock lock --mamba -k env -p $CONDA_PLATFORM -e "$extras" -f pyproject.toml $spec_opts
gh_out environment-file "conda-$CONDA_PLATFORM.lock.yml"
if [ "$mode" = install ]; then
msg "Creating Conda environment"
vr mamba env create -n "$env_name" -f conda-$CONDA_PLATFORM.lock.yml
gh_out environment-name "$env_name"
fi