/
lint.py
executable file
·61 lines (53 loc) · 2.38 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
#!/usr/bin/env python3
from helpers.pylint import get_score, look_for, find_warnings, find_errors, run_adjustables, lint_all
from helpers.automation_tools import read_json, write_json
import sys
import argparse
# See pyGSTi/doc/pylint.md!
# Fail if the score is below a threshold
def check_score(on=lint_all):
jsonFile = 'config/pylint_config.json'
config = read_json(jsonFile)
desiredScore = config['desired-score']
print('Score should be: %s' % desiredScore)
score = get_score(on)
print('Score was: %s' % score)
if on == lint_all:
if float(score) >= float(desiredScore):
config['desired-score'] = score # Update the score if it is higher than the last one
write_json(config, jsonFile)
sys.exit(0)
else:
sys.exit(1)
else:
if score < 10:
sys.exit(1)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Lint pygsti')
parser.add_argument('specific', nargs='*',
help='lint for specific items')
parser.add_argument('--score', '-s', action='store_true',
help='check the current repo\'s score against the last-highest score')
parser.add_argument('--errors', '-e', action='store_true',
help='check for errors in the repo')
parser.add_argument('--noerrors', '-n', action='store_true',
help='fail if any errors are found in core pygsti repo (not tests)')
parser.add_argument('--warnings', '-w', action='store_true',
help='check for warnings in the repo')
parser.add_argument('--adjustables', '-a', action='store_true',
help='check for refactors in the repo')
parser.add_argument('--andtests', '-t', action='store_true',
help='include tests in specific items being linted for')
parsed = parser.parse_args(sys.argv[1:])
if parsed.score:
check_score()
if parsed.noerrors:
check_score(find_errors) # Call find_errors to score by instead of lint_all
elif parsed.errors: # Doesn't need to run if no-errors already did
find_errors(coreonly=False)
if parsed.warnings:
find_warnings()
if parsed.adjustables:
run_adjustables()
if parsed.specific != []:
look_for(parsed.specific, not parsed.andtests)