diff --git a/contrib/check-py3-compat.py b/contrib/check-py3-compat.py --- a/contrib/check-py3-compat.py +++ b/contrib/check-py3-compat.py @@ -12,8 +12,8 @@ from __future__ import absolute_import, import ast import sys -def check_compat(f): - """Check Python 3 compatibility for a file.""" +def check_compat_py2(f): + """Check Python 3 compatibility for a file with Python 2""" with open(f, 'rb') as fh: content = fh.read() root = ast.parse(content) @@ -36,8 +36,24 @@ def check_compat(f): if haveprint and 'print_function' not in futures: print('%s requires print_function' % f) +def check_compat_py3(f): + """Check Python 3 compatibility of a file with Python 3.""" + with open(f, 'rb') as fh: + content = fh.read() + + try: + ast.parse(content) + except SyntaxError as e: + print('%s: invalid syntax: %s' % (f, e)) + return + if __name__ == '__main__': + if sys.version_info[0] == 2: + fn = check_compat_py2 + else: + fn = check_compat_py3 + for f in sys.argv[1:]: - check_compat(f) + fn(f) sys.exit(0) diff --git a/tests/test-check-py3-compat.t b/tests/test-check-py3-compat.t --- a/tests/test-check-py3-compat.t +++ b/tests/test-check-py3-compat.t @@ -118,3 +118,46 @@ tests/test-walkrepo.py requires print_function tests/test-wireproto.py requires print_function tests/tinyproxy.py requires print_function + +#if py3exe + $ hg files 'set:(**.py)' | sed 's|\\|/|g' | xargs $PYTHON3 contrib/check-py3-compat.py + contrib/check-code.py: invalid syntax: (unicode error) 'unicodeescape' codec can't decode bytes in position 18-19: malformed \N character escape (, line 106) + contrib/import-checker.py: invalid syntax: Missing parentheses in call to 'print' (, line 569) + contrib/revsetbenchmarks.py: invalid syntax: invalid syntax (, line 186) + doc/hgmanpage.py: invalid syntax: invalid syntax (, line 286) + hgext/color.py: invalid syntax: invalid syntax (, line 551) + mercurial/archival.py: invalid syntax: invalid syntax (, line 234) + mercurial/bundle2.py: invalid syntax: invalid syntax (, line 977) + mercurial/commands.py: invalid syntax: invalid syntax (, line 3324) + tests/filterpyflakes.py: invalid syntax: Missing parentheses in call to 'print' (, line 61) + tests/generate-working-copy-states.py: invalid syntax: Missing parentheses in call to 'print' (, line 69) + tests/get-with-headers.py: invalid syntax: Missing parentheses in call to 'print' (, line 44) + tests/readlink.py: invalid syntax: invalid syntax (, line 7) + tests/seq.py: invalid syntax: Missing parentheses in call to 'print' (, line 23) + tests/silenttestrunner.py: invalid syntax: Missing parentheses in call to 'print' (, line 11) + tests/test-ancestor.py: invalid syntax: Missing parentheses in call to 'print' (, line 187) + tests/test-batching.py: invalid syntax: invalid syntax (, line 34) + tests/test-bdiff.py: invalid syntax: invalid syntax (, line 10) + tests/test-context.py: invalid syntax: invalid syntax (, line 21) + tests/test-demandimport.py: invalid syntax: invalid syntax (, line 26) + tests/test-duplicateoptions.py: invalid syntax: invalid syntax (, line 34) + tests/test-filecache.py: invalid syntax: Missing parentheses in call to 'print' (, line 23) + tests/test-filelog.py: invalid syntax: Missing parentheses in call to 'print' (, line 33) + tests/test-hg-parseurl.py: invalid syntax: invalid syntax (, line 4) + tests/test-hgweb-auth.py: invalid syntax: invalid syntax (, line 24) + tests/test-hybridencode.py: invalid syntax: invalid syntax (, line 5) + tests/test-lrucachedict.py: invalid syntax: invalid syntax (, line 6) + tests/test-minirst.py: invalid syntax: Missing parentheses in call to 'print' (, line 6) + tests/test-parseindex2.py: invalid syntax: Missing parentheses in call to 'print' (, line 173) + tests/test-propertycache.py: invalid syntax: Missing parentheses in call to 'print' (, line 50) + tests/test-revlog-ancestry.py: invalid syntax: Missing parentheses in call to 'print' (, line 49) + tests/test-status-inprocess.py: invalid syntax: Missing parentheses in call to 'print' (, line 8) + tests/test-trusted.py: invalid syntax: invalid syntax (, line 60) + tests/test-ui-color.py: invalid syntax: invalid syntax (, line 11) + tests/test-ui-config.py: invalid syntax: invalid syntax (, line 32) + tests/test-ui-verbosity.py: invalid syntax: Missing parentheses in call to 'print' (, line 9) + tests/test-walkrepo.py: invalid syntax: invalid syntax (, line 37) + tests/test-wireproto.py: invalid syntax: invalid syntax (, line 55) + tests/tinyproxy.py: invalid syntax: Missing parentheses in call to 'print' (, line 53) + +#endif