forked from ESCOMP/CTSM
-
Notifications
You must be signed in to change notification settings - Fork 10
/
py_env_create
executable file
·140 lines (132 loc) · 3.86 KB
/
py_env_create
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/bin/bash
#
# py_env_create -- 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".
#
dir=${0%/*}
if [ "$dir" = "$0" ];then
dir="."
fi
# Check if conda is in your path
conda --help >& condahelp.txt
error=$?
if [ $error != 0 ]; then
echo "conda is NOT in your path for the bash shell add it with modules or whatever is required on your system to get it in your path"
echo "on Derecho/capser/etc use -- module load conda"
echo "on izumi/CGD systems use -- module unload lang/python; module load lang/anaconda/23.11.0/base"
echo "For notes on installing on a user system see: https://docs.conda.io/projects/conda/en/latest/user-guide/install/index.html"
echo "Error code was $error"
cat condahelp.txt
rm condahelp.txt
exit -1
fi
rm condahelp.txt
ctsm_python=ctsm_pylib
condadir="$dir/python"
domain=`domainname`
condafile="conda_env_ctsm_py.txt"
#----------------------------------------------------------------------
# Usage subroutine
usage() {
echo ""
echo "***********************************************************************"
echo "usage:"
echo "./py_env_create"
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 "[-f|--file <file>] "
echo " Conda environment requirements text file to use (text format) in addition to the others"
echo " Assumed to be under the directory: $condadir"
echo " Default is: $condafile"
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"
;;
-f|--file )
condafile=$2
shift
;;
--option )
option=$2
shift
;;
* )
echo "ERROR:: invalid argument sent in: $2"
usage
exit 1
;;
esac
shift
done
#
# Error checking options and setup
#
if [ ! -f $condadir/$condafile ]; then
echo "$condadir/$condafile does NOT exist"
echo "Use the --file option with a valid filename"
exit -1
fi
echo "Use conda to install the python environment needed to run the CTSM python tools in the conda environment: $ctsm_python"
echo "Using the file: $condadir/$condafile"
#
# 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"
cmd="conda create --force --name $ctsm_python --quiet"
echo "$cmd"
$cmd
if [ $? != 0 ]; then
echo "Error creating conda environment $ctsm_python"
exit -1
fi
else
echo "$ctsm_python environment already exists"
fi
#
# Install the environemnt
#
echo "Install $ctsm_python this can take a long time (12 to 20 minutes is expected), be patient...."
echo " ...."
echo " ...."
echo " ...."
verbosity="--quiet"
loglevel="ERROR"
if [ "$verbose" == "Yes" ]; then
verbosity="--verbose"
loglevel="INFO"
fi
cmd="conda install --yes $verbosity --channel conda-forge --name $ctsm_python --file $condadir/$condafile $option"
echo "$cmd"
$cmd
if [ $? != 0 ]; then
echo "Trouble installing the $ctsm_python python environment"
echo "There must be a problem in the $condadir/$condafile conda specification environment file"
echo "Change the file and try again"
exit -2
fi
#
# Report on success
#
echo "Successfully installed the $ctsm_python python environment"
echo
echo "activate the environment by doing the following..."
echo "conda activate $ctsm_python"