forked from brainiak/brainiak
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pr-check.sh
executable file
·163 lines (135 loc) · 4.04 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/bin/bash
# Copyright 2016 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Check readiness for pull request
set -e
if [ ! -f brainiak/__init__.py ]
then
echo "Run "$(basename "$0")" from the root of the BrainIAK hierarchy."
exit 1
fi
basedir=$(pwd)
function create_venv_venv {
python3 -m venv ../$1
}
function activate_venv_venv {
source ../$1/bin/activate
}
function deactivate_venv_venv {
deactivate
}
function remove_venv_venv {
rm -r ../$1
}
function create_conda_venv {
conda create -n $1 --yes python=3.6
}
function activate_conda_venv {
source activate $1
# Pip may update setuptools while installing BrainIAK requirements and
# break the Conda cached package, which breaks subsequent runs.
conda install --yes -f setuptools
}
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
$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"
else
create_venv=create_venv_venv
activate_venv=activate_venv_venv
deactivate_venv=deactivate_venv_venv
remove_venv=remove_venv_venv
fi
# Check if running in an sdist
if git ls-files --error-unmatch pr-check.sh 2> /dev/null
then
git clean -Xf .
else
sdist_mode="--sdist-mode"
fi
venv=$(mktemp -u brainiak_pr_venv_XXXXX) || \
exit_with_error "mktemp -u error"
$create_venv $venv || {
exit_with_error "Virtual environment creation failed."
}
$activate_venv $venv || {
$remove_venv $venv
exit_with_error "Virtual environment activation failed."
}
python3 -m pip install -U pip || \
exit_with_error_and_venv "Failed to update Pip."
# install brainiak in editable mode (required for testing)
# brainiak will also be installed together with the developer dependencies, but
# we install it first here to check that installation succeeds without the
# developer dependencies.
python3 -m pip install $ignore_installed -U -e . || \
exit_with_error_and_venv "Failed to install BrainIAK."
# install developer dependencies
python3 -m pip install $ignore_installed -U -r requirements-dev.txt || \
exit_with_error_and_venv "Failed to install development requirements."
# Source a user-specified Bash script to customize the installation.
# This option is not supported and should not be documented in user docs.
# In particular we use it on our CentOS 6 Jenkins server with .conda/bin/
customization_script_flag=$1
if [ ${customization_script_flag:-default} = "--customization-script" ]
then
customization_script=$2
if [ ${customization_script:-default} = "default" ]
then
exit_with_error_and_venv "Must specify customization script"
else
source $customization_script
fi
fi
# static analysis
./run-checks.sh || \
exit_with_error_and_venv "run-checks failed"
# run tests
./run-tests.sh $sdist_mode || \
exit_with_error_and_venv "run-tests failed"
# build documentation
cd docs
export THEANO_FLAGS='device=cpu,floatX=float64,blas.ldflags=-lblas'
if [ ! -z $SLURM_NODELIST ]
then
make_wrapper="srun -n 1"
fi
$make_wrapper make || {
cd -
exit_with_error_and_venv "make docs failed"
}
cd -
$deactivate_venv
$remove_venv $venv
echo "pr-check finished successfully."