forked from quiltdata/quilt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpylint_git_commit_hook.sh
51 lines (47 loc) · 1.2 KB
/
pylint_git_commit_hook.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
#!/bin/bash
# This script can be use git commit hook
# Place script as .git/hooks/pre-commit
PYLINT_VERSION='1.7.2'
PYLINT_ARGS='--enable=W,E --disable=C'
EXIT_ON_WARNING_ERROR=1
# Use 0 if need to avoid pylint failure and proceed to 'git commit'
#
# Checking.. if pylint install
#
python -c "import pylint"
if [[ $? -ne 0 ]]
then
echo "$0: Pylint not installed!"
echo "$0: Do pip install pylint==$PYLINT_VERSION"
exit 1
fi
#
# Checking pylint version, (easy to parse pip freeze than pylint --version)
#
pylint_version=$(pip freeze | grep pylint | awk -F'==' '{ print $2 }')
if [[ $pylint_version != $PYLINT_VERSION ]]
then
echo "$0: Pylint version mismatch!"
echo "$0: Do pip install pylint==$PYLINT_VERSION"
exit 1
fi
#
# Checking for specified directories inside repo
#
for i in "registry" "compiler"
do
echo "$0: Checking $i directory.."
# purpose of changing directory is to use already existing pylintrc as default pylint config
pushd $i && find . -iname "*.py" | xargs pylint $PYLINT_ARGS >> /dev/null
if [[ $? -ne 0 ]]
then
echo "$0: Pylint failed in $i!"
if [[ $EXIT_ON_WARNING_ERROR -eq 1 ]]
then
echo "$0: Stop iterating.."
exit 1
fi
fi
popd
# otherwise hook exit with 0
done