mirror of https://github.com/ansible/ansible.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
867 B
Python
34 lines
867 B
Python
8 years ago
|
#!/usr/bin/env python
|
||
|
"""Python syntax checker with lint friendly output."""
|
||
5 years ago
|
from __future__ import (absolute_import, division, print_function)
|
||
|
__metaclass__ = type
|
||
8 years ago
|
|
||
|
import parser
|
||
|
import sys
|
||
|
|
||
|
|
||
|
def main():
|
||
|
status = 0
|
||
|
|
||
7 years ago
|
for path in sys.argv[1:] or sys.stdin.read().splitlines():
|
||
6 years ago
|
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()
|
||
8 years ago
|
|
||
|
try:
|
||
|
parser.suite(source)
|
||
|
except SyntaxError:
|
||
5 years ago
|
ex = sys.exc_info()[1]
|
||
8 years ago
|
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()
|