-
Notifications
You must be signed in to change notification settings - Fork 101
/
Copy pathlint-python
executable file
·66 lines (58 loc) · 1.9 KB
/
lint-python
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
61
62
63
64
65
66
#!/usr/bin/env bash
# Run pylint on a subset of the code, alternatively pass files as arguments.
# Exit on error
set -e
# Exit on pipe fail
set -o pipefail
PYLINT=${PYLINT:-pylint}
command -v ${PYLINT} >/dev/null 2>&1 || { echo >&2 "${PYLINT} is missing"; exit 1; }
MYPY=${MYPY:-mypy}
command -v ${MYPY} >/dev/null 2>&1 || { echo >&2 "${MYPY} is missing"; exit 1; }
# Store files as array in ARGS
ARGS=($(find py releases -name '*.py' | grep -v -e generated -e old))
# implicit-reexport: `from foo import bar` re-exports (normal Python3 behavior), otherwise mypy
# expects `from foo import bar as bar`.
# namespace-packages: follow imports in subfolders without `__init__.py` (also normal Python3
# behavior).
# We must typecheck the whole `py` directory even if only a few files are modified so that mypy
# sees all types
${MYPY} --implicit-reexport --namespace-packages --ignore-missing-imports --strict py/send_message.py py/bitbox02/bitbox02 releases/describe_signed_firmware.py
# Must run from root directory where .pylintrc is
# We ignore refactor and convention messages because they can differ with `black`
${PYLINT} --persistent=no "${ARGS[@]}" || {
# pylint returns a bitmask as status code:
#
# 0 no error
# 1 fatal message issued
# 2 error message issued
# 4 warning message issued
# 8 refactor message issued
# 16 convention message issued
# 32 usage error
pylint_status=$?
exitcode=0
if (( ${pylint_status} & 1 )); then
echo fatal message >&2
exitcode=2
fi
if (( ${pylint_status} & 2 )); then
echo error message >&2
exitcode=2
fi
if (( ${pylint_status} & 4 )); then
echo warning message >&2
exitcode=2
fi
if (( ${pylint_status} & 8 )); then
echo refactor message >&2
fi
if (( ${pylint_status} & 16 )); then
echo convention message >&2
fi
# This should not happen!
if (( ${pylint_status} & 32 )); then
echo usage error >&2
exitcode=2
fi
exit ${exitcode}
}