2022-01-16 08:24:05 +08:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2015-08-05 04:45:41 +08:00
|
|
|
import argparse
|
|
|
|
import ast
|
2017-07-06 03:38:21 +08:00
|
|
|
import platform
|
2015-08-05 04:45:41 +08:00
|
|
|
import sys
|
|
|
|
import traceback
|
2024-10-12 07:30:07 +08:00
|
|
|
from collections.abc import Sequence
|
2015-08-05 04:45:41 +08:00
|
|
|
|
|
|
|
|
2022-01-16 08:24:05 +08:00
|
|
|
def main(argv: Sequence[str] | None = None) -> int:
|
2015-08-05 04:45:41 +08:00
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument('filenames', nargs='*')
|
|
|
|
args = parser.parse_args(argv)
|
|
|
|
|
|
|
|
retval = 0
|
|
|
|
for filename in args.filenames:
|
|
|
|
|
|
|
|
try:
|
2018-06-18 15:00:38 +08:00
|
|
|
with open(filename, 'rb') as f:
|
|
|
|
ast.parse(f.read(), filename=filename)
|
2015-08-05 04:45:41 +08:00
|
|
|
except SyntaxError:
|
2020-02-06 03:10:42 +08:00
|
|
|
impl = platform.python_implementation()
|
|
|
|
version = sys.version.split()[0]
|
|
|
|
print(f'{filename}: failed parsing with {impl} {version}:')
|
2020-02-04 00:41:48 +08:00
|
|
|
tb = ' ' + traceback.format_exc().replace('\n', '\n ')
|
2020-02-06 03:10:42 +08:00
|
|
|
print(f'\n{tb}')
|
2015-08-05 04:45:41 +08:00
|
|
|
retval = 1
|
|
|
|
return retval
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2021-10-24 01:23:50 +08:00
|
|
|
raise SystemExit(main())
|