Skip to content

Commit c0fe53a

Browse files
committed
tests: pylint: add pylint
Add a pylint integration, we have increasing amount of python.. Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 54e060c commit c0fe53a

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

tests/patch/pylint/info.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"run": ["pylint.sh"]
3+
}

tests/patch/pylint/pylint.sh

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
4+
HEAD=$(git rev-parse HEAD)
5+
tmpfile_o=$(mktemp)
6+
tmpfile_n=$(mktemp)
7+
rc=0
8+
9+
pr() {
10+
echo " ====== $@ ======" | tee -a /dev/stderr
11+
}
12+
13+
# If it doesn't touch .py files, don't bother. Ignore created and deleted.
14+
if ! git show --diff-filter=AM --pretty="" --name-only HEAD | grep -q -E "\.py$"
15+
then
16+
echo "No python scripts touched, skip" >&$DESC_FD
17+
exit 0
18+
fi
19+
20+
echo "Redirect to $tmpfile_o and $tmpfile_n"
21+
22+
echo "Tree base:"
23+
git log -1 --pretty='%h ("%s")' HEAD~
24+
echo "Now at:"
25+
git log -1 --pretty='%h ("%s")' HEAD
26+
27+
pr "Checking before the patch"
28+
git checkout -q HEAD~
29+
30+
for f in $(git show --diff-filter=M --pretty="" --name-only HEAD | grep -E "\.py$"); do
31+
pylint $f | tee -a $tmpfile_o
32+
done
33+
34+
incumbent=$(grep -i -c ": E[0-9][0-9][0-9][0-9]: " $tmpfile_o)
35+
incumbent_w=$(grep -i -c ": [WC][0-9][0-9][0-9][0-9]: " $tmpfile_o)
36+
37+
pr "Checking the tree with the patch"
38+
git checkout -q $HEAD
39+
40+
for f in $(git show --diff-filter=AM --pretty="" --name-only HEAD | grep -E "\.py$"); do
41+
pylint $f | tee -a $tmpfile_n
42+
done
43+
44+
current=$(grep -i -c ": E[0-9][0-9][0-9][0-9]: " $tmpfile_n)
45+
current_w=$(grep -i -c ": [WC][0-9][0-9][0-9][0-9]: " $tmpfile_n)
46+
47+
echo "Errors before: $incumbent (+warn: $incumbent_w) this patch: $current (+warn: $current_w)" >&$DESC_FD
48+
49+
if [ $current -gt $incumbent ]; then
50+
echo "New errors added" 1>&2
51+
diff -U 0 $tmpfile_o $tmpfile_n 1>&2
52+
53+
rc=1
54+
fi
55+
56+
if [ $current_w -gt $incumbent_w ]; then
57+
echo "New warnings added" 1>&2
58+
59+
rc=250
60+
fi
61+
62+
rm "$tmpfile_o" "$tmpfile_n"
63+
64+
exit $rc

0 commit comments

Comments
 (0)