forked from fabric8-analytics/fabric8-analytics-rudra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-docstyle.sh
executable file
·80 lines (63 loc) · 1.88 KB
/
check-docstyle.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
#!/bin/bash
IFS=$'\n'
# list of directories with sources to check
directories=$(cat directories.txt)
# list of separate files to check
separate_files=$(cat files.txt)
pass=0
fail=0
function prepare_venv() {
VIRTUALENV=$(which virtualenv) || :
if [ -z "$VIRTUALENV" ]; then
# python34 which is in CentOS does not have virtualenv binary
VIRTUALENV=$(which virtualenv-3)
fi
${VIRTUALENV} -p python3 venv && source venv/bin/activate && python3 "$(which pip3)" install pydocstyle
}
# run the pydocstyle for all files that are provided in $1
function check_files() {
for source in $1
do
echo "$source"
pydocstyle --count "$source"
if [ $? -eq 0 ]
then
echo " Pass"
let "pass++"
elif [ $? -eq 2 ]
then
echo " Illegal usage (should not happen)"
exit 2
else
echo " Fail"
let "fail++"
fi
done
}
echo "----------------------------------------------------"
echo "Checking documentation strings in all sources stored"
echo "in 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)
check_files "$files"
done
echo
echo "----------------------------------------------------"
echo "Checking documentation strings in the following files"
echo "$separate_files"
echo "----------------------------------------------------"
check_files "$separate_files"
if [ $fail -eq 0 ]
then
echo "All checks passed for $pass source files"
else
let total=$pass+$fail
echo "Documentation strings should be added and/or fixed in $fail source files out of $total files"
exit 1
fi