forked from MRtrix3/mrtrix3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_pylint
executable file
·115 lines (88 loc) · 2.55 KB
/
run_pylint
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
#!/bin/bash
# Copyright (c) 2008-2022 the MRtrix3 contributors.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Covered Software is provided under this License on an "as is"
# basis, without warranty of any kind, either expressed, implied, or
# statutory, including, without limitation, warranties that the
# Covered Software is free of defects, merchantable, fit for a
# particular purpose or non-infringing.
# See the Mozilla Public License v. 2.0 for more details.
#
# For more details, see http://www.mrtrix.org/.
LOGFILE=pylint.log
echo logging to \""$LOGFILE"\"
# generate list of tests to run:
tests="build configure update_copyright"
if [ $# == 0 ]; then
for lib_path in lib/mrtrix3/*; do
if [[ -d ${lib_path} && ! ( ${lib_path} == *"__pycache__"* ) ]]; then
for src_file in ${lib_path}/*.py; do
if [[ -f ${src_file} ]]; then
tests="$tests $src_file"
fi
done
elif [[ ${lib_path} == *.py ]]; then
tests="$tests $lib_path"
fi
done
for bin_path in bin/*; do
if [ -f ${bin_path} ] && $(head -n1 ${bin_path} | grep -q "#!/usr/bin/env python"); then
tests="$tests $bin_path"
fi
done
else
tests="$@"
fi
success=0
ntests=0
if [ -z $PYTHON ]; then
forcepyversion=""
else
echo "Using pylint for "${PYTHON}" (from PYTHON environment variable)"
forcepyversion="$PYTHON -m "
fi
cat > $LOGFILE <<EOD
-------------------------------------------
Version information
-------------------------------------------
EOD
eval ${forcepyversion} pylint --version >> $LOGFILE
cat >> $LOGFILE <<EOD
-------------------------------------------
Testing MRtrix3 Python scripts
-------------------------------------------
EOD
export PYTHONPATH="$(pwd)/lib:$PYTHONPATH"
for file in $tests; do
cat >> $LOGFILE <<EOD
-------------------------------------------
## testing "${file}"...
EOD
echo -n 'testing "'${file}'"... '
eval ${forcepyversion} pylint --rcfile=testing/pylint.rc ${file} > .__tmp.log 2>&1
if [[ $? -ne 0 ]]; then
echo 'ERROR'
echo " [ ERROR ]" >> $LOGFILE
else
echo 'OK'
echo " [ ok ]" >> $LOGFILE
((success++))
fi
cat .__tmp.log >> $LOGFILE
echo "" >> $LOGFILE
((ntests++))
done
if [[ ${success} -lt ${ntests} ]]; then
cat >> $LOGFILE <<EOD
## ERROR: $(($ntests-$success)) of $(($ntests)) tests failed (see \""$LOGFILE"\")
EOD
exit 1
else
cat >> $LOGFILE <<EOD
## $ntests tests completed OK
EOD
fi