-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathenv.sh
More file actions
executable file
·57 lines (54 loc) · 1.56 KB
/
env.sh
File metadata and controls
executable file
·57 lines (54 loc) · 1.56 KB
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
#!/bin/bash
set -e
if command -v conda &> /dev/null; then
eval "$(conda shell.bash hook)"
MGR="conda"
else
echo "Please install conda/mamba first!"
exit 1
fi
if command -v mamba &> /dev/null; then
# shellcheck disable=SC1091
source "${CONDA_EXE%/*}/../etc/profile.d/mamba.sh"
MGR="mamba"
fi
if [ "${1}" = "create" ]; then
if [ ! -d ".renv" ]; then mkdir ".renv"; fi
"${MGR}" env create -p ./conda -f conda.yaml
(
"${MGR}" activate ./conda
"${MGR}" env config vars set PKG_CONFIG_PATH="${CONDA_PREFIX}/lib/pkgconfig:${PKG_CONFIG_PATH}"
"${MGR}" env config vars set R_PROFILE_USER="$(pwd -P)/.Rprofile"
"${MGR}" env config vars set RENV_PATHS_ROOT="$(pwd -P)/.renv"
)
(
"${MGR}" activate ./conda
Rscript -e "renv::restore()"
Rscript -e "IRkernel::installspec(prefix='${CONDA_PREFIX}', rprofile='${R_PROFILE_USER}')"
)
(
"${MGR}" activate ./conda
flit install -s
)
(
"${MGR}" activate ./conda
pre-commit install
)
elif [ "${1}" = "export" ]; then
"${MGR}" env export -p ./conda --no-build | \
yq -y 'del(.name, .prefix, .variables) | del(.dependencies[].pip?[] | select(startswith("cascade")))' \
> conda.yaml
(
"${MGR}" activate ./conda
Rscript -e "renv::snapshot()"
)
elif [ "${1}" = "update" ]; then
"${MGR}" env update -p ./conda -f conda.yaml
(
"${MGR}" activate ./conda
Rscript -e "renv::restore()"
)
else
echo "Usage: ${0} <create|export|update>"
exit 1
fi