-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathsetupPythonEnvironment.bash
More file actions
executable file
·240 lines (203 loc) · 6.15 KB
/
setupPythonEnvironment.bash
File metadata and controls
executable file
·240 lines (203 loc) · 6.15 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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#!/bin/bash
# Configuration
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
PYTHON_TARGET=
BIN_DIR=
PACKAGE_DIR=
TMP_CLONE_DIR=
PIP_CMD="pip --disable-pip-version-check"
PACKAGE_BRANCH=main
declare -a TARGET_PACKAGES=("geos-utils"
"geos-mesh"
"geos-xml-tools"
"hdf5-wrapper"
"pygeos-tools"
"geos-ats")
declare -a LINK_SCRIPTS=("preprocess_xml"
"format_xml"
"convert_abaqus"
"run_geos_ats"
"setup_ats_environment"
"geos_ats_log_check"
"geos_ats_restart_check"
"geos_ats_curve_check"
"geos_ats_process_tests_fails"
"mesh-doctor"
"activate"
"python")
# Read input arguments
if [[ -z "${VERBOSE}" ]]
then
VERBOSE=false
else
VERBOSE=true
fi
while [[ $# > 0 ]]
do
key="$1"
case $key in
-p|--python-target)
PYTHON_TARGET="$2"
shift # past argument
;;
-b|--bin-dir)
BIN_DIR="$2"
shift # past argument
;;
-d|--pkg-dir)
PACKAGE_DIR="$2"
shift # past argument
;;
-r|--python-pkg-branch)
PACKAGE_BRANCH="$2"
shift # past argument
;;
-v|--verbose)
VERBOSE=true
shift # past argument
;;
-?|--help)
echo ""
echo "Python environment setup options:"
echo "-p/--python-target \"Target parent python bin\""
echo "-b/--bin-dir \"Directory to link new scripts\""
echo "-d/--pkg-dir \"Directory containing target python packages\""
echo "-r/--python-pkg-branch \"Target branch for geosPythonPackages (default=main) \""
echo "-v/--verbose \"Increase verbosity level\""
echo ""
exit
;;
--default)
DEFAULT=YES
;;
*)
# unknown option
;;
esac
shift # past argument or value
done
# Check to make sure that the python target exists
echo "Checking the python target..."
if [[ -z "${PYTHON_TARGET}" ]]
then
echo "To setup the python environment, please specify the python executable path"
exit 1
fi
if [ ! -f "$PYTHON_TARGET" ]
then
echo "The target python executable ($PYTHON_TARGET) cannot be found"
exit 1
fi
# Check for a predefined package directory
echo "Checking for python packages..."
if [[ -z "${PACKAGE_DIR}" ]]
then
echo "Cloning the GEOS python package repository (branch=$PACKAGE_BRANCH)..."
TMP_CLONE_DIR=$(mktemp -d)
PACKAGE_DIR=$TMP_CLONE_DIR/geosPythonPackages
git clone --depth 1 --branch $PACKAGE_BRANCH --single-branch https://github.com/GEOS-DEV/geosPythonPackages.git $PACKAGE_DIR
elif [ ! -d "${PACKAGE_DIR}/geosx_xml_tools_package" ]
then
echo "The specified package directory does not contain the expected targets."
echo "The path specified with -d/--pkg-dir should point to a copy of the geosPythonPackages repository."
exit 1
fi
# Updating pip
echo "Updating pip"
$PYTHON_TARGET -m pip install --upgrade pip setuptools wheel
# Install packages
echo "Installing python packages..."
for p in "${TARGET_PACKAGES[@]}"
do
if [ -d "$PACKAGE_DIR/$p" ]
then
echo " $p"
# Try installing the package
if $VERBOSE
INSTALL_MSG=$($PYTHON_TARGET -m $PIP_CMD install --upgrade $PACKAGE_DIR/$p)
INSTALL_RC=$?
then
INSTALL_MSG=$($PYTHON_TARGET -m $PIP_CMD install --upgrade $PACKAGE_DIR/$p 2>&1)
INSTALL_RC=$?
fi
if [ $INSTALL_RC -ne 0 ]
then
echo $INSTALL_MSG
if [[ $INSTALL_MSG =~ "HTTP error" ]]
then
echo "The setup script may have failed to fetch external dependencies"
echo "Try re-running the \"make ats_environment\" script again on a machine that can access github"
else
echo "Failed to install packages"
echo "Note: if you do not have write access for your target python environment,"
echo "consider using a virtual python environment. See these instructions for details:"
echo "https://docs.python.org/3/library/venv.html"
fi
exit $INSTALL_RC
fi
else
echo "Could not find target package: $p"
fi
done
# Link key scripts to the bin directory
declare -a MOD_SEARCH_PATH=("$(dirname $PYTHON_TARGET)"
"$HOME/.local/bin"
"$HOME/local/bin")
if [ -n "${BIN_DIR}" ]
then
echo "Linking key scripts to bin directory..."
for p in "${LINK_SCRIPTS[@]}"
do
echo " $p"
if $VERBOSE
then
echo " searching the following paths:"
fi
package_found="0"
for MOD_PATH in "${MOD_SEARCH_PATH[@]}"
do
# Check to see if the tool exists
pp=
if $VERBOSE
then
echo " $MOD_PATH/$p"
fi
if [ -f "$MOD_PATH/$p" ]
then
pp="$MOD_PATH/$p"
fi
# Remove any old links if necessary
if [ -f "$BIN_DIR/$p" ]
then
rm $BIN_DIR/$p
fi
# Create links
if [ ! -z "$pp" ]
then
if $VERBOSE
then
echo " (found $p as $pp)"
fi
ln -s $pp $BIN_DIR/$p
package_found="1"
break
fi
done
if [[ "$package_found" == "0" ]]
then
echo " (could not find where $p is installed)"
fi
done
# Link additional tools from the scripts directory
echo "Linking additional scripts to the bin directory..."
if [ ! -f "$BIN_DIR/geosx_preprocessed" ]
then
ln -s $SCRIPT_DIR/automatic_xml_preprocess.sh $BIN_DIR/geosx_preprocessed
ln -s $SCRIPT_DIR/pygeosx_preprocess.py $BIN_DIR/pygeosx_preprocess.py
fi
fi
if [[ ! -z "${TMP_CLONE_DIR}" ]]
then
rm -rf $TMP_CLONE_DIR
fi
echo "Done!"