ansible/test/sanity/compile/compile.py
Matt Clay 6645054329
Code cleanup for test infrastructure. (#59046)
* Remove useless object inheritance in test code.
* Remove unnecessary pass statements from test code.
* Comment on why certain pylint rules are ignored.
* Add more pylint test contexts.
* Fix import order.
* Remove unused variables.
* Remove unnecessary pass statement.
* Fix bad continuations.
* Remove unnecessary elif.
* Allow legitimate broad except statements.
* Allow legitimate protected access.
* Clean up names to make pylint pass.
2019-07-12 13:17:20 -07:00

33 lines
867 B
Python
Executable file

#!/usr/bin/env python
"""Python syntax checker with lint friendly output."""
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import parser
import sys
def main():
status = 0
for path in sys.argv[1:] or sys.stdin.read().splitlines():
with open(path, 'rb') as source_fd:
if sys.version_info[0] == 3:
source = source_fd.read().decode('utf-8')
else:
source = source_fd.read()
try:
parser.suite(source)
except SyntaxError:
ex = sys.exc_info()[1]
status = 1
message = ex.text.splitlines()[0].strip()
sys.stdout.write("%s:%d:%d: SyntaxError: %s\n" % (path, ex.lineno, ex.offset, message))
sys.stdout.flush()
sys.exit(status)
if __name__ == '__main__':
main()