-
Notifications
You must be signed in to change notification settings - Fork 0
/
lint.py
53 lines (43 loc) · 1.27 KB
/
lint.py
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
"""
Git Hook that trigger on pre-commit. It run Pylint on all changed files within the
repository and execute the tests if the user is about to commit on the branch dev or
main.
"""
import argparse
import logging
import sys
from pylint import lint
def main():
logging.getLogger().setLevel(logging.INFO)
parser = argparse.ArgumentParser(prog="LINT")
parser.add_argument(
"-p",
"--path",
nargs="+",
help="paths to directory to run Pylint.",
default=["examples", "src", "tests"],
type=str,
)
parser.add_argument(
"-t",
"--threshold",
help="Score threshold to fail Pylint.",
default=10.0,
type=float,
)
args = parser.parse_args()
paths = args.path
threshold = args.threshold
logging.info(
"Running Pylint within %s, will pass if the score is over: %s", paths, threshold
)
result = lint.Run(["--rcfile=pylintrc", *paths], do_exit=False)
rating = result.linter.stats.global_note
if rating < threshold and result.linter.stats.statement > 0:
logging.error("Pylint failed, you must have a rating over %s/10.", threshold)
sys.exit(1)
else:
logging.info("Pylint passed.")
if __name__ == "__main__":
main()
sys.exit(0)