forked from fabric8-analytics/f8a-hpf-insights
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-linter.sh
executable file
·57 lines (49 loc) · 1.48 KB
/
run-linter.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
#!/bin/bash
directories="deployments training src tests perf_tests PoC_code"
pass=0
fail=0
function prepare_venv() {
VIRTUALENV=$(which virtualenv)
if [ $? -eq 1 ]; then
# python34 which is in CentOS does not have virtualenv binary
VIRTUALENV=$(which virtualenv-3)
fi
if [ $? -eq 1 ]; then
# still don't have virtual environment -> use python3.4 directly
python3.4 -m venv venv && source venv/bin/activate && python3 "$(which pip3)" install pycodestyle
else
${VIRTUALENV} -p python3 venv && source venv/bin/activate && python3 "$(which pip3)" install pycodestyle
fi
}
echo "----------------------------------------------------"
echo "Running Python linter against following directories:"
echo "$directories"
echo "----------------------------------------------------"
echo
[ "$NOVENV" == "1" ] || prepare_venv || exit 1
# checks for the whole directories
for directory in $directories
do
files=$(find "$directory" -path "$directory/venv" -prune -o -name '*.py' -print)
for source in $files
do
echo "$source"
pycodestyle "$source"
if [ $? -eq 0 ]
then
echo " Pass"
let "pass++"
else
echo " Fail"
let "fail++"
fi
done
done
if [ $fail -eq 0 ]
then
echo "All checks passed for $pass source files"
else
let total=$pass+$fail
echo "Linter fail, $fail source files out of $total source files need to be fixed"
exit 1
fi