2017-03-08 05:27:50 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
"""Python syntax checker with lint friendly output."""
|
2019-07-12 08:46:20 +02:00
|
|
|
from __future__ import (absolute_import, division, print_function)
|
|
|
|
__metaclass__ = type
|
2017-03-08 05:27:50 +01:00
|
|
|
|
|
|
|
import parser
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
status = 0
|
|
|
|
|
2018-02-28 00:05:39 +01:00
|
|
|
for path in sys.argv[1:] or sys.stdin.read().splitlines():
|
2019-07-02 17:56:12 +02:00
|
|
|
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()
|
2017-03-08 05:27:50 +01:00
|
|
|
|
|
|
|
try:
|
|
|
|
parser.suite(source)
|
|
|
|
except SyntaxError:
|
2019-07-12 22:17:20 +02:00
|
|
|
ex = sys.exc_info()[1]
|
2017-03-08 05:27:50 +01:00
|
|
|
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()
|