-
Notifications
You must be signed in to change notification settings - Fork 3
/
pystan-install.sh
158 lines (150 loc) · 4.48 KB
/
pystan-install.sh
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
#!/bin/bash
#
# pystan-install.sh
#
# Download the archieved PyStan2 source repository, switch to the CVODES branch, and build and install into
# the current Python environment.
#
BUILD_ROOT="./"
VERBOSE=""
NO_CLONE=0
function doCmd() {
local output error_str forced_rc rc cmd_rc verbose no_exit
local no_output_capture success_str
forced_rc=0
verbose=0
no_exit=0
no_output_capture=0
while [ $# -gt 0 ]; do
case "$1" in
--no-output-capture|-O)
no_output_capture=1
;;
--no-exit|-E)
no_exit=1
;;
--success-string|-s)
shift
if [ $# -eq 0 ]; then
echo "ERROR: no argument to --success-string/-s in doCmd()"
exit 22
fi
success_str="$1"
;;
--error-string|-e)
shift
if [ $# -eq 0 ]; then
echo "ERROR: no argument to --error-string/-e in doCmd()"
exit 22
fi
error_str="$1"
;;
--rc|-r)
shift
if [ $# -eq 0 ]; then
echo "ERROR: no argument to --rc/-r in doCmd()"
exit 22
fi
forced_rc=1
rc="$1"
;;
--verbose|-v)
verbose=1
;;
*)
break
;;
esac
shift
done
if [ $# -gt 0 ]; then
if [ $no_output_capture -eq 0 ]; then
output="$("$@" 2>&1)"
cmd_rc=$?
else
"$@"
cmd_rc=$?
fi
if [ $cmd_rc -ne 0 ]; then
if [ -n "$error_str" ]; then
echo "ERROR: $error_str"
if [ $verbose -ne 0 ]; then
printf " %s" "$output"
fi
fi
if [ $no_exit -eq 0 ]; then
if [ $forced_rc -ne 0 ]; then
exit $rc
fi
exit $cmd_rc
fi
if [ $forced_rc -ne 0 ]; then
return $rc
fi
return $cmd_rc
fi
fi
if [ -n "$success_str" ]; then
echo "$success_str"
fi
return 0
}
function usage() {
cat <<EOT
usage:
$1 {--verbose|-v} {--help|-h} {--build-root|-p <path>}
{--no-clone|-C}
EOT
exit 0
}
while [ $# -gt 0 ]; do
case "$1" in
--help|-h)
usage "$0"
;;
--verbose|-v)
VERBOSE="-v"
;;
--no-clone|-C)
NO_CLONE=1
;;
--build-root|-p)
shift
if [ $# -eq 0 ]; then
echo "ERROR: no argument provided with --build-root/-p"
exit 22
fi
BUILD_ROOT="$1"
;;
*)
break
;;
esac
shift
done
if [ ! -d "$BUILD_ROOT" ]; then
echo "ERROR: build root directory does not exist: $BUILD_ROOT"
exit 1
fi
BUILD_DIR="${BUILD_ROOT}/pystan-src"
CURRENT_DIR="$(pwd)"
if [ $NO_CLONE -eq 0 ]; then
doCmd $VERBOSE -e "failed to clone PyStan2 github repository" -s "OK - cloned git repository" \
git clone --recursive https://github.com/stan-dev/pystan2 "$BUILD_DIR"
fi
pushd "$BUILD_DIR" >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "ERROR: unable to change to PyStan2 source directory: $BUILD_DIR"
exit 1
fi
doCmd $VERBOSE -e "unable to checkout CVODES branch" -s "OK - checked-out cvodes branch" \
git checkout cvodes
doCmd $VERBOSE -e "unable to update submodules in repository" -s "OK - updated submodules in repository" \
git submodule update --recursive
doCmd $VERBOSE -e "failed while cleaning unneeded components from source repository" -s "OK - removed unneeded components from repository" \
python -c "\"import os, shutil; [shutil.rmtree(r'\\?\{}'.format(os.path.abspath(dirname)), ignore_errors=True) for dirname in [dirname for dirname, *_ in os.walk('pystan/stan') if any(dirname.endswith(ends) for ends in ['doc', 'test'])]]\""
doCmd $VERBOSE -e "failed while building PyStan2+CVODES module" -s "OK - PyStan2+CVODES module built" \
python setup.py build
doCmd $VERBOSE -e "failed while installing PyStan2+CVODES module" -s "OK - PyStan2+CVODES module installed" \
python setup.py install
popd >/dev/null 2>&1