-
Notifications
You must be signed in to change notification settings - Fork 3
/
lint.py
57 lines (42 loc) · 1.59 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
54
55
56
57
"""This code is mainly available in
https://medium.com/@doedotdev/pylint-static-code-analysis-python-script-with-adjustable-threshold-b0d6d2c8647b
and was only modified to suit the project"""
import argparse
import logging
from pylint.lint import Run
logging.getLogger().setLevel(logging.INFO)
parser = argparse.ArgumentParser(prog="LINT")
parser.add_argument('-p',
'--path',
help='path to directory you want to run pylint | '
'Default: %(default)s | '
'Type: %(type)s ',
default='./winx_sistema/winx_sistema',
type=str)
parser.add_argument('-t',
'--threshold',
help='score threshold to fail pylint runner | '
'Default: %(default)s | '
'Type: %(type)s ',
default=5,
type=float)
args = parser.parse_args()
path = str(args.path)
threshold = float(args.threshold)
logging.info('PyLint Starting | '
'Path: {} | '
'Threshold: {} '.format(path, threshold))
results = Run([path], do_exit=False)
final_score = results.linter.stats['global_note']
if final_score < threshold:
message = ('PyLint Failed | '
'Score: {} | '
'Threshold: {} '.format(final_score, threshold))
logging.error(message)
raise Exception(message)
else:
message = ('PyLint Passed | '
'Score: {} | '
'Threshold: {} '.format(final_score, threshold))
logging.info(message)
exit(0)