forked from flexcompute/tidy3d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlint.py
62 lines (44 loc) · 1.53 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
58
59
60
61
62
""" python lint.py -p path -t t lints files at `path` with passing threshold of `t` (0-10) """
import argparse
import logging
from pylint.lint import Run
# wont pass until score (out of 10.0) is greater than this
DEFAULT_THRESHOLD = 10.0
def main():
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="./tidy3d",
type=str,
)
parser.add_argument(
"-t",
"--threshold",
help="score threshold to fail pylint runner | Default: %(default)s | " "Type: %(type)s ",
default=DEFAULT_THRESHOLD,
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)
try:
final_score = results.linter.stats.global_note
except AttributeError:
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)
if __name__ == "__main__":
main()