-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconda.env.build
More file actions
67 lines (55 loc) · 1.97 KB
/
conda.env.build
File metadata and controls
67 lines (55 loc) · 1.97 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
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
CONDA_SHELL=$(readlink -f $(dirname $CONDA_EXE)/../etc/profile.d/conda.sh)
source $CONDA_SHELL
# Define ANSI color codes as environment variables
RED='\033[0;31m'
BLUE='\033[0;34m'
RESET='\033[0m'
# Check if environment.yml exists
if [[ ! -f "environment.yml" ]]; then
echo -e "${RED}[x] error: environment.yml not found in the current directory!${RESET}"
exit 1
fi
# Extract the environment name from the environment.yml file
ENV_NAME=$(grep -m 1 "^name:" environment.yml | awk '{print $2}')
if [[ -z "$ENV_NAME" ]]; then
echo -e "${RED}[x] error: Environment name not found in environment.yml!${RESET}"
exit 1
fi
echo "[i] environment name found: $ENV_NAME"
# Check if a Conda environment is currently active
if [[ -n "$CONDA_DEFAULT_ENV" ]]; then
echo "[i] deactivating currently active environment: $CONDA_DEFAULT_ENV"
conda activate base
if [[ $? -ne 0 ]]; then
echo -e "${RED}[x] error: Failed to deactivate environment $CONDA_DEFAULT_ENV!${RESET}"
exit 1
fi
else
echo "[i] no conda environment currently active. Proceeding..."
fi
# Remove the environment if it exists
if conda env list | grep -q "^$ENV_NAME\s"; then
echo "[i] removing existing environment: $ENV_NAME"
conda env remove -n "$ENV_NAME" -y
if [[ $? -ne 0 ]]; then
echo -e "${RED}[x] error: Failed to remove environment $ENV_NAME!${RESET}"
exit 1
fi
else
echo "[i] environment $ENV_NAME does not exist. Skipping removal."
fi
# Recreate the environment
echo "[i] creating environment $ENV_NAME from environment.yml"
conda env create -f environment.yml
if [[ $? -eq 0 ]]; then
echo "[i] environment $ENV_NAME recreated successfully."
else
echo -e "${RED}[x] error: Failed to create environment $ENV_NAME!${RESET}"
exit 1
fi
############################## post-install ##############################
if [ -f ./conda/post-install.sh ]; then
echo "[i] running post-install script"
bash ./conda/post-install.sh ${ENV_NAME}
fi