forked from brainiak/brainiak-extras
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpr-check.sh
executable file
·145 lines (121 loc) · 3.5 KB
/
pr-check.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
#!/bin/bash
# Copyright 2016 Intel Corporation
#
# This file is part of brainiak-extras.
#
# brainiak-extras is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# brainiak-extras is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with brainiak-extras. If not, see <http://www.gnu.org/licenses/>.
# Check readiness for pull request
set -e
if [ ! -f brainiak_extras/__init__.py ]
then
echo "Run "$(basename "$0")" from the root of the BrainIAK-extras repository"
exit 1
fi
basedir=$(pwd)
function create_virtualenv_venv {
virtualenv ../$1
}
function activate_virtualenv_venv {
source ../$1/bin/activate
}
function deactivate_virtualenv_venv {
deactivate
}
function remove_virtualenv_venv {
rm -r ../$1
}
function create_conda_venv {
conda create -n $1 --yes python=3
}
function activate_conda_venv {
source activate $1
# Anaconda does not provide pip3 (at least on our Jenkins machine,
# Metacortex), so we install it in the virtual environment.
pip install -I pip
}
function deactivate_conda_venv {
source deactivate
}
function remove_conda_venv {
conda env remove -n $1 --yes
}
function exit_with_error {
echo $1 >&2
exit 1
}
function exit_with_error_and_venv {
$deactivate_venv
cd $basedir
rm -f .coverage.*
$remove_venv $venv
exit_with_error "$1"
}
if [ $(which conda) ]
then
export PYTHONNOUSERSITE=True
create_venv=create_conda_venv
activate_venv=activate_conda_venv
deactivate_venv=deactivate_conda_venv
remove_venv=remove_conda_venv
ignore_installed="--ignore-installed"
elif [ $(which virtualenv) ]
then
create_venv=create_virtualenv_venv
activate_venv=activate_virtualenv_venv
deactivate_venv=deactivate_virtualenv_venv
remove_venv=remove_virtualenv_venv
else
echo "Cannot find virtualenv or conda."
echo "You must install one of them or test manually."
exit 1
fi
# optional, but highly recommended: create a virtualenv to isolate tests
venv=$(mktemp -u brainiak_pr_venv_XXXXX) || \
exit_with_error "mktemp -u error"
$create_venv $venv || {
exit_with_error "virtualenv creation failed"
}
$activate_venv $venv || {
$remove_venv $venv
exit_with_error "virtualenv activation failed"
}
# install brainiak in editable mode (required for testing)
pip3 install --process-dependency-links $ignore_installed -U -e . || \
exit_with_error_and_venv "pip3 failed to install BrainIAK-extras"
# install developer dependencies
pip3 install $ignore_installed -U -r requirements-dev.txt || \
exit_with_error_and_venv "pip3 failed to install requirements"
# static analysis
./run-checks.sh || \
exit_with_error_and_venv "run-checks failed"
# run tests
./run-tests.sh || \
exit_with_error_and_venv "run-tests failed"
# build documentation
cd docs
export THEANO_FLAGS='device=cpu,floatX=float64'
git clean -Xf .
if [ ! -z $SLURM_NODELIST ]
then
make_wrapper="srun -n 1"
fi
$make_wrapper make || {
cd -
exit_with_error_and_venv "make docs failed"
}
cd -
# optional: remove virtualenv
$deactivate_venv
$remove_venv $venv
echo "Check successful"