Fix lintstack.py with Python3
The pylint target was switched to python3, but I didn't realize that it's not really working. This change should make lintstack.py compatible with Python 3. Related note: we should find a unified solution for all repositories which have a local copy of lintstack.py/lintstack.sh instead of duplicating this code over and over. Change-Id: I5727e33f8ac40347e47e4f5f4e64579897a66f6f
This commit is contained in:
parent
0674ad72bd
commit
5eeb783ccd
|
@ -106,9 +106,9 @@ class ErrorKeys(object):
|
|||
|
||||
@classmethod
|
||||
def print_json(cls, errors, output=sys.stdout):
|
||||
print >>output, "# automatically generated by tools/lintstack.py"
|
||||
print("# automatically generated by tools/lintstack.py", file=output)
|
||||
for i in sorted(errors.keys()):
|
||||
print >>output, json.dumps(i)
|
||||
print(json.dumps(i), output)
|
||||
|
||||
@classmethod
|
||||
def from_file(cls, filename):
|
||||
|
@ -131,7 +131,7 @@ def run_pylint():
|
|||
|
||||
|
||||
def generate_error_keys(msg=None):
|
||||
print "Generating", KNOWN_PYLINT_EXCEPTIONS_FILE
|
||||
print("Generating", KNOWN_PYLINT_EXCEPTIONS_FILE)
|
||||
if msg is None:
|
||||
msg = run_pylint()
|
||||
errors = LintOutput.from_msg_to_dict(msg)
|
||||
|
@ -140,41 +140,40 @@ def generate_error_keys(msg=None):
|
|||
|
||||
|
||||
def validate(newmsg=None):
|
||||
print "Loading", KNOWN_PYLINT_EXCEPTIONS_FILE
|
||||
print("Loading", KNOWN_PYLINT_EXCEPTIONS_FILE)
|
||||
known = ErrorKeys.from_file(KNOWN_PYLINT_EXCEPTIONS_FILE)
|
||||
if newmsg is None:
|
||||
print "Running pylint. Be patient..."
|
||||
print("Running pylint. Be patient...")
|
||||
newmsg = run_pylint()
|
||||
errors = LintOutput.from_msg_to_dict(newmsg)
|
||||
|
||||
print "Unique errors reported by pylint: was %d, now %d." \
|
||||
% (len(known), len(errors))
|
||||
print("Unique errors reported by pylint: was %d, now %d."
|
||||
% (len(known), len(errors)))
|
||||
passed = True
|
||||
for err_key, err_list in errors.items():
|
||||
for err in err_list:
|
||||
if err_key not in known:
|
||||
print err.lintoutput
|
||||
print
|
||||
print(err.lintoutput, '\n')
|
||||
passed = False
|
||||
if passed:
|
||||
print "Congrats! pylint check passed."
|
||||
print("Congrats! pylint check passed.")
|
||||
redundant = known - set(errors.keys())
|
||||
if redundant:
|
||||
print "Extra credit: some known pylint exceptions disappeared."
|
||||
print("Extra credit: some known pylint exceptions disappeared.")
|
||||
for i in sorted(redundant):
|
||||
print json.dumps(i)
|
||||
print "Consider regenerating the exception file if you will."
|
||||
print(json.dumps(i))
|
||||
print("Consider regenerating the exception file if you will.")
|
||||
else:
|
||||
print ("Please fix the errors above. If you believe they are false"
|
||||
print("Please fix the errors above. If you believe they are false"
|
||||
" positives, run 'tools/lintstack.py generate' to overwrite.")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def usage():
|
||||
print """Usage: tools/lintstack.py [generate|validate]
|
||||
print("""Usage: tools/lintstack.py [generate|validate]
|
||||
To generate pylint_exceptions file: tools/lintstack.py generate
|
||||
To validate the current commit: tools/lintstack.py
|
||||
"""
|
||||
""")
|
||||
|
||||
|
||||
def main():
|
||||
|
|
Loading…
Reference in New Issue