3 # Simple pre-commit hook to check that there are no errors in the fdroidserver
6 # Redirect output to stderr.
9 PY_FILES="fdroid makebuildserver setup.py examples/*.py buildserver/*.py fdroidserver/*.py"
10 PY_TEST_FILES="tests/*.TestCase"
11 SH_FILES="hooks/pre-commit"
12 BASH_FILES="fd-commit jenkins-build docs/update.sh completion/bash-completion"
13 RB_FILES="buildserver/cookbooks/*/recipes/*.rb"
15 # In the default configuration, the checks E123, E133, E226, E241 and E242 are
16 # ignored because they are not rules unanimously accepted
17 # On top of those, we ignore:
18 # * E501: line too long (82 > 79 characters)
19 # - Recommended for readability but not enforced
20 # - Some lines are awkward to wrap around a char limit
21 # * W503: line break before binary operator
25 PEP8_IGNORE="E123,E133,E226,E241,E242,E501,W503"
33 command -v $1 1>/dev/null
36 if cmd_exists pyflakes-python2; then
37 PYFLAKES=pyflakes-python2
38 elif cmd_exists pyflakes; then
41 err "pyflakes is not installed!"
44 if cmd_exists pep8-python2; then
46 elif cmd_exists pep8; then
49 err "pep8 is not installed!"
52 if ! $PYFLAKES $PY_FILES $PY_TEST_FILES; then
53 err "pyflakes tests failed!"
56 if ! $PEP8 --ignore=$PEP8_IGNORE $PY_FILES; then
57 err "pep8 tests failed!"
60 # The tests use a little hack in order to cleanly import the fdroidserver
61 # package locally like a regular package. pep8 doesn't see that, so this
62 # makes pep8 skip E402 on the test files that need that hack.
63 if ! $PEP8 --ignore=$PEP8_IGNORE,E402 $PY_TEST_FILES; then
64 err "pep8 tests failed!"
68 for f in $SH_FILES; do
70 err "dash tests failed!"
74 for f in $BASH_FILES; do
76 err "bash tests failed!"
80 for f in $RB_FILES; do
81 if ! ruby -c $f 1>/dev/null; then
82 err "ruby tests failed!"