forked from ASPP/pelita
-
Notifications
You must be signed in to change notification settings - Fork 0
/
summary.sh
executable file
·61 lines (54 loc) · 2.4 KB
/
summary.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
#!/bin/zsh
# Small script to do a QA of the code. Will print total lines of code, the
# summary score of pylint and the results of testing. This is designed to give a
# one page, easy-to-read summary of a few code quality metrics.
do_wc(){
# LOC does not count blanklines
LOC=$( find $@ -name '*.py' -print0 | xargs -0 sed "/^\s*$/d" |
wc -l | tail -1 | sed 's/total//' )
# LOC-COM counts comments. Comments are lines whose first non-blank character
# is a single '#'. Lines where the first two non-blank characters are
# '##' are not counted as comments [we use that for maze layouts].
COM=$( find $@ -name '*.py' -print0 | xargs -0 sed "/^\s*$/d" |
# put a placeholder in front of lines with '##'
sed "s/^\s*##.*$/PLACEHOLDER/" |
# now remove comments
sed "/^\s*#.*$/d" | wc -l | tail -1 | sed 's/total//' )
PERCENT=$(echo "scale=1;$(( $LOC - $COM ))*100/$LOC"|bc)
print $LOC of which $(( $LOC - $COM )) \($PERCENT\%\) are comments
}
do_pylint(){
print $( pylint $@ &> /dev/null |
grep 'Your code' |
sed 's/Your\ code\ has\ been\ rated at\ \([^ ]*\) .*$/\1/' )
}
echo "Project summary / QA for pelita"
echo "----------------------------------------------------------------------"
echo "Lines of code:"
for d in pelita test pelita/messaging; do
printf "%30s : %20s\n" $d "$( do_wc $d )"
done
echo ""
if ! which pylint &> /dev/null ; then
echo "pylint not found in path! Can't do style checker!"
else
echo "Running pylint... please stand by!"
echo "Pylint score:"
echo " for pelita/ : "$(do_pylint pelita/**/*.py )
echo " for test/ : "$( do_pylint test/**/*.py )
echo " for both/ : "$( do_pylint {pelita,test}/**/*.py )
fi
if ! which nosetests &> /dev/null ; then
echo "'nosetests' not found in path! Can't run tests!"
else
echo ""
echo "Running tests... please stand by!"
test_stats=$( nosetests --with-cov --cover-package pelita 2>&1 >/dev/null)
echo " Total number of tests : "$( echo $test_stats |
grep 'Ran'|
sed 's/Ran\ \(.*\)\ tests.*/\1/' )
echo " # assert statements : "$( grep 'assert' test/**/*.py | wc -l)
echo " Test coverage : "$( echo $test_stats |
grep 'TOTAL' | sed 's/TOTAL.*\(......$\)/\1/')
echo " Result : "$( echo $test_stats | tail -1)
fi