forked from ESCOMP/CTSM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage_python_env
executable file
·89 lines (83 loc) · 2.64 KB
/
manage_python_env
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
#!/bin/bash -f
#
# manage_python_env -- setup the python environment in order to use CTSM python tools
#
# Simple bash script to setup the python environment for the user so they can run the CTSM
# python tools using "conda".
#
# Check if conda is in your path
conda --help >& /dev/null
if [ $? != 0 ]; then
echo "conda is NOT in your path add it with modules or whatever is required on your system to get it in your path"
echo "on cheyenne use -- module load conda"
exit -1
fi
ctsm_python=ctsm_py
#----------------------------------------------------------------------
# Usage subroutine
usage() {
echo ""
echo "***********************************************************************"
echo "usage:"
echo "./manage_python_env"
echo ""
echo "valid arguments: "
echo "[-h|--help] "
echo " Displays this help message"
echo "[-v|--verbose] "
echo " Run with verbose mode for the install so you see the progress bar"
echo "[--option <option>] "
echo " Option(s) to pass to 'conda install' step"
echo "***********************************************************************"
}
verbose="No"
option=""
while [ $# -gt 0 ]; do
case $1 in
-h|--help )
usage
exit 0
;;
-v|--verbose )
verbose="Yes"
;;
--option )
option=$2
shift
;;
* )
echo "ERROR:: invalid argument sent in: $2"
usage
exit 1
;;
esac
shift
done
echo "Use conda to install the python environment needed to run the CTSM python tools in the conda environment: $ctsm_python"
# Check if the environment already exists, if it does continue, if not create it
conda list -n $ctsm_python >& /dev/null
if [ $? != 0 ]; then
echo "Create $ctsm_python"
conda create -n $ctsm_python
else
echo "$ctsm_python environment already exists"
fi
echo "Install $ctsm_python this can take a long time, be patient...."
verbosity="-q"
if [ "$verbose" == "Yes" ]; then
verbosity="-v"
fi
conda install --yes $verbosity -n $ctsm_python --file python/conda_env_ctsm_py.txt $option
if [ $? != 0 ]; then
echo "Trouble installing the $ctsm_python python environment"
exit -2
fi
echo "Activate $ctsm_python"
conda activate $ctsm_python
if [ $? != 0 ]; then
echo "Trouble activating the $ctsm_python python environment fix as outlined above and then run"
echo "conda activate $ctsm_python"
echo "On CGD systems for tcsh you need to source the conda.csh under the /etc/profile.d/ subdirectory of the /usr/local/anaconda-* version you are using for python"
exit -3
fi
echo "Successfully installed the $ctsm_python python environment"