forked from Pyomo/pyomo
-
Notifications
You must be signed in to change notification settings - Fork 2
/
.jenkins.sh
206 lines (192 loc) · 6.51 KB
/
.jenkins.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
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
#!/usr/bin/env bash
# Important environment variables:
#
# WORKSPACE: path to the base WORKSPACE. This script assumes that there
# are 2 available subdirectories: pyomo (the pyomo source checkout
# and pyomo-model-libraries
# (the checkout of the additional model libraries repo). It will
# create two additional directories within WORKSPACE: python (a
# virtualenv) and config (the local Pyomo configuration/cache
# directory)
#
# CATEGORY: the category to pass to pyomo.common.unittest (defaults to nightly)
#
# TEST_SUITES: Paths (module or directory) to be passed to nosetests to
# run. (defaults to "pyomo '$WORKSPACE/pyomo-model-libraries'")
#
# SLIM: If nonempty, then the virtualenv will only have pip, setuptools,
# and wheel installed. Otherwise the virtualenv will inherit the
# system site-packages.
#
# CODECOV_TOKEN: the token to use when uploading results to codecov.io
#
# CODECOV_ARGS: additional arguments to pass to the codecov uploader
# (e.g., to support SSL certificates)
#
# DISABLE_COVERAGE: if nonempty, then coverage analysis is disabled
#
# PYOMO_SETUP_ARGS: passed to the 'python setup.py develop' command
# (e.g., to specify --with-cython)
#
# PYOMO_DOWNLOAD_ARGS: passed to the 'pyomo download-extensions" command
# (e.g., to set up local SSL certificate authorities)
#
if test -z "$WORKSPACE"; then
export WORKSPACE=`pwd`
fi
if test -z "$CATEGORY"; then
export CATEGORY=nightly
fi
if test -z "$TEST_SUITES"; then
export TEST_SUITES="pyomo ${WORKSPACE}/pyomo-model-libraries ${WORKSPACE}/pyomo/examples/pyomobook"
fi
if test -z "$SLIM"; then
export VENV_SYSTEM_PACKAGES='--system-site-packages'
fi
if test "$WORKSPACE" != "`pwd`"; then
echo "ERROR: pwd is not WORKSPACE"
echo " pwd= `pwd`"
echo " WORKSPACE= $WORKSPACE"
exit 1
fi
MODE="$1"
if test -z "$MODE" -o "$MODE" == setup; then
# Clean old PYC files and remove any previous virtualenv
echo "#"
echo "# Removing python virtual environment"
echo "#"
rm -rf ${WORKSPACE}/python
echo "#"
echo "# Cleaning out old .pyc and cython files"
echo "#"
for EXT in pyc pyx pyd so dylib dll; do
find ${WORKSPACE}/pyomo -name \*.$EXT -delete
done
# Set up the local lpython
echo ""
echo "#"
echo "# Setting up virtual environment"
echo "#"
virtualenv python $VENV_SYSTEM_PACKAGES --clear
source python/bin/activate
# Because modules set the PYTHONPATH, we need to make sure that the
# virtualenv appears first
LOCAL_SITE_PACKAGES=`python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"`
export PYTHONPATH="$LOCAL_SITE_PACKAGES:$PYTHONPATH"
# Set up Pyomo checkouts
echo ""
# configure the Pyomo configuration directory
echo "#"
echo "# Installing pyomo modules"
echo "#"
popd
pushd "$WORKSPACE/pyomo" || exit 1
python setup.py develop $PYOMO_SETUP_ARGS || exit 1
popd
#
# DO NOT install pyomo-model-libraries
#
# Set up coverage tracking for subprocesses
if test -z "$DISABLE_COVERAGE"; then
# Clean up old coverage files
rm -fv ${WORKSPACE}/pyomo/.coverage ${WORKSPACE}/pyomo/.coverage.*
# Set up coverage for this build
export COVERAGE_PROCESS_START=${WORKSPACE}/coveragerc
cp ${WORKSPACE}/pyomo/.coveragerc ${COVERAGE_PROCESS_START}
echo "data_file=${WORKSPACE}/pyomo/.coverage" \
>> ${COVERAGE_PROCESS_START}
echo 'import coverage; coverage.process_startup()' \
> "${LOCAL_SITE_PACKAGES}/run_coverage_at_startup.pth"
fi
# Move into the pyomo directory
pushd ${WORKSPACE}/pyomo || exit 1
# Set a local Pyomo configuration dir within this workspace
export PYOMO_CONFIG_DIR="${WORKSPACE}/config"
echo ""
echo "PYOMO_CONFIG_DIR=$PYOMO_CONFIG_DIR"
echo ""
# Use Pyomo to download & compile binary extensions
i=0
while /bin/true; do
i=$[$i+1]
echo "Downloading pyomo extensions (attempt $i)"
pyomo download-extensions $PYOMO_DOWNLOAD_ARGS
if test $? == 0; then
break
elif test $i -ge 3; then
exit 1
fi
DELAY=$(( RANDOM % 30 + 15))
echo "Pausing $DELAY seconds before re-attempting download"
sleep $DELAY
done
pyomo build-extensions || exit 1
# Print useful version information
echo ""
echo "#"
echo "# Package information:"
echo "#"
python --version
pip --version
pip list
echo "#"
echo "# Installed programs:"
echo "#"
gjh -v || echo "GJH not found"
glpsol -v || echo "GLPK not found"
cbc -quit || echo "CBC not found"
cplex -c quit || echo "CPLEX not found"
gurobi_cl --version || echo "GUROBI not found"
ipopt -v || echo "IPOPT not found"
gams || echo "GAMS not found"
# Exit ${WORKSPACE}/pyomo
popd
fi
if test -z "$MODE" -o "$MODE" == test; then
# Move into the pyomo directory
pushd ${WORKSPACE}/pyomo || exit 1
echo ""
echo "#"
echo "# Running Pyomo tests"
echo "#"
python -m pyomo.common.unittest $TEST_SUITES -v --cat=$CATEGORY --xunit
# Combine the coverage results and upload
if test -z "$DISABLE_COVERAGE"; then
echo ""
echo "#"
echo "# Processing coverage information in "`pwd`
echo "#"
#
# Note, that the PWD should still be $WORKSPACE/pyomo
#
coverage combine || exit 1
coverage report -i
export OS=`uname`
if test -z "$CODECOV_TOKEN"; then
coverage xml
else
CODECOV_JOB_NAME=`echo ${JOB_NAME} | sed -r 's/^(.*autotest_)?Pyomo_([^\/]+).*/\2/'`.$BUILD_NUMBER.$python
i=0
while /bin/true; do
i=$[$i+1]
echo "Uploading coverage to codecov (attempt $i)"
codecov -X gcovcodecov -X gcov -X s3 --no-color \
-t $CODECOV_TOKEN --root `pwd` -e OS,python \
--name $CODECOV_JOB_NAME $CODECOV_ARGS \
| tee .cover.upload
if test $? == 0 -a `grep -i error .cover.upload \
| grep -v branch= | wc -l` -eq 0; then
break
elif test $i -ge 4; then
exit 1
fi
DELAY=$(( RANDOM % 30 + 15))
echo "Pausing $DELAY seconds before re-attempting upload"
sleep $DELAY
done
fi
rm .coverage
fi
# Exit ${WORKSPACE}/pyomo
popd
fi