-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcheck-style.sh
executable file
·43 lines (35 loc) · 1.17 KB
/
check-style.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
#!/bin/bash
# Usage:
# ./check-style.sh
# `- Checks all the files.
#
# ./check-style.sh --changed
# `- Checks only the files that were changed in this branch.
#
# ./check-style.sh file1.py file2.py ...
# `- Checks only the given files.
set -eu
script_path=$(cd "$(dirname "${0}")" && pwd)
if test "${1-}" = '--changed'; then
files_to_search="$(git diff --name-only "$(git merge-base origin/master "$(git rev-parse --abbrev-ref HEAD)")")"
shift
else
files_to_search='forge src tests'
fi
cd "${script_path}"
if test ${#} -eq 0; then
PY_FILES="$(find ${files_to_search} -name '*.py' -or -name 'forge' | sort -uV)"
if test -z "${PY_FILES}"; then echo "No python scripts to check. Exiting early."; exit 0; fi
else
PY_FILES="${@}"
fi
printf 'Checking %s files...\n' "$(printf '%s\n' "${PY_FILES}" | wc -w)"
printf '======== pylint ========\n'
pylint -j "$(nproc || gnproc || echo 1)" --rcfile=pylint.rc ${PY_FILES} || pylint_failed=true
printf '===== pycodestyle ======\n'
pycodestyle --max-line-length=3000 ${PY_FILES}
# This trick is so that both linters are run, while the script still exits
# with non-zero code if one of them fails.
if test -n "${pylint_failed+x}"; then
exit 1
fi