Show More
@@ -12,8 +12,8 b' from __future__ import absolute_import, ' | |||||
12 | import ast |
|
12 | import ast | |
13 | import sys |
|
13 | import sys | |
14 |
|
14 | |||
15 | def check_compat(f): |
|
15 | def check_compat_py2(f): | |
16 |
"""Check Python 3 compatibility for a file |
|
16 | """Check Python 3 compatibility for a file with Python 2""" | |
17 | with open(f, 'rb') as fh: |
|
17 | with open(f, 'rb') as fh: | |
18 | content = fh.read() |
|
18 | content = fh.read() | |
19 | root = ast.parse(content) |
|
19 | root = ast.parse(content) | |
@@ -36,8 +36,24 b' def check_compat(f):' | |||||
36 | if haveprint and 'print_function' not in futures: |
|
36 | if haveprint and 'print_function' not in futures: | |
37 | print('%s requires print_function' % f) |
|
37 | print('%s requires print_function' % f) | |
38 |
|
38 | |||
|
39 | def check_compat_py3(f): | |||
|
40 | """Check Python 3 compatibility of a file with Python 3.""" | |||
|
41 | with open(f, 'rb') as fh: | |||
|
42 | content = fh.read() | |||
|
43 | ||||
|
44 | try: | |||
|
45 | ast.parse(content) | |||
|
46 | except SyntaxError as e: | |||
|
47 | print('%s: invalid syntax: %s' % (f, e)) | |||
|
48 | return | |||
|
49 | ||||
39 | if __name__ == '__main__': |
|
50 | if __name__ == '__main__': | |
|
51 | if sys.version_info[0] == 2: | |||
|
52 | fn = check_compat_py2 | |||
|
53 | else: | |||
|
54 | fn = check_compat_py3 | |||
|
55 | ||||
40 | for f in sys.argv[1:]: |
|
56 | for f in sys.argv[1:]: | |
41 |
|
|
57 | fn(f) | |
42 |
|
58 | |||
43 | sys.exit(0) |
|
59 | sys.exit(0) |
@@ -118,3 +118,46 b'' | |||||
118 | tests/test-walkrepo.py requires print_function |
|
118 | tests/test-walkrepo.py requires print_function | |
119 | tests/test-wireproto.py requires print_function |
|
119 | tests/test-wireproto.py requires print_function | |
120 | tests/tinyproxy.py requires print_function |
|
120 | tests/tinyproxy.py requires print_function | |
|
121 | ||||
|
122 | #if py3exe | |||
|
123 | $ hg files 'set:(**.py)' | sed 's|\\|/|g' | xargs $PYTHON3 contrib/check-py3-compat.py | |||
|
124 | contrib/check-code.py: invalid syntax: (unicode error) 'unicodeescape' codec can't decode bytes in position 18-19: malformed \N character escape (<unknown>, line 106) | |||
|
125 | contrib/import-checker.py: invalid syntax: Missing parentheses in call to 'print' (<unknown>, line 569) | |||
|
126 | contrib/revsetbenchmarks.py: invalid syntax: invalid syntax (<unknown>, line 186) | |||
|
127 | doc/hgmanpage.py: invalid syntax: invalid syntax (<unknown>, line 286) | |||
|
128 | hgext/color.py: invalid syntax: invalid syntax (<unknown>, line 551) | |||
|
129 | mercurial/archival.py: invalid syntax: invalid syntax (<unknown>, line 234) | |||
|
130 | mercurial/bundle2.py: invalid syntax: invalid syntax (<unknown>, line 977) | |||
|
131 | mercurial/commands.py: invalid syntax: invalid syntax (<unknown>, line 3324) | |||
|
132 | tests/filterpyflakes.py: invalid syntax: Missing parentheses in call to 'print' (<unknown>, line 61) | |||
|
133 | tests/generate-working-copy-states.py: invalid syntax: Missing parentheses in call to 'print' (<unknown>, line 69) | |||
|
134 | tests/get-with-headers.py: invalid syntax: Missing parentheses in call to 'print' (<unknown>, line 44) | |||
|
135 | tests/readlink.py: invalid syntax: invalid syntax (<unknown>, line 7) | |||
|
136 | tests/seq.py: invalid syntax: Missing parentheses in call to 'print' (<unknown>, line 23) | |||
|
137 | tests/silenttestrunner.py: invalid syntax: Missing parentheses in call to 'print' (<unknown>, line 11) | |||
|
138 | tests/test-ancestor.py: invalid syntax: Missing parentheses in call to 'print' (<unknown>, line 187) | |||
|
139 | tests/test-batching.py: invalid syntax: invalid syntax (<unknown>, line 34) | |||
|
140 | tests/test-bdiff.py: invalid syntax: invalid syntax (<unknown>, line 10) | |||
|
141 | tests/test-context.py: invalid syntax: invalid syntax (<unknown>, line 21) | |||
|
142 | tests/test-demandimport.py: invalid syntax: invalid syntax (<unknown>, line 26) | |||
|
143 | tests/test-duplicateoptions.py: invalid syntax: invalid syntax (<unknown>, line 34) | |||
|
144 | tests/test-filecache.py: invalid syntax: Missing parentheses in call to 'print' (<unknown>, line 23) | |||
|
145 | tests/test-filelog.py: invalid syntax: Missing parentheses in call to 'print' (<unknown>, line 33) | |||
|
146 | tests/test-hg-parseurl.py: invalid syntax: invalid syntax (<unknown>, line 4) | |||
|
147 | tests/test-hgweb-auth.py: invalid syntax: invalid syntax (<unknown>, line 24) | |||
|
148 | tests/test-hybridencode.py: invalid syntax: invalid syntax (<unknown>, line 5) | |||
|
149 | tests/test-lrucachedict.py: invalid syntax: invalid syntax (<unknown>, line 6) | |||
|
150 | tests/test-minirst.py: invalid syntax: Missing parentheses in call to 'print' (<unknown>, line 6) | |||
|
151 | tests/test-parseindex2.py: invalid syntax: Missing parentheses in call to 'print' (<unknown>, line 173) | |||
|
152 | tests/test-propertycache.py: invalid syntax: Missing parentheses in call to 'print' (<unknown>, line 50) | |||
|
153 | tests/test-revlog-ancestry.py: invalid syntax: Missing parentheses in call to 'print' (<unknown>, line 49) | |||
|
154 | tests/test-status-inprocess.py: invalid syntax: Missing parentheses in call to 'print' (<unknown>, line 8) | |||
|
155 | tests/test-trusted.py: invalid syntax: invalid syntax (<unknown>, line 60) | |||
|
156 | tests/test-ui-color.py: invalid syntax: invalid syntax (<unknown>, line 11) | |||
|
157 | tests/test-ui-config.py: invalid syntax: invalid syntax (<unknown>, line 32) | |||
|
158 | tests/test-ui-verbosity.py: invalid syntax: Missing parentheses in call to 'print' (<unknown>, line 9) | |||
|
159 | tests/test-walkrepo.py: invalid syntax: invalid syntax (<unknown>, line 37) | |||
|
160 | tests/test-wireproto.py: invalid syntax: invalid syntax (<unknown>, line 55) | |||
|
161 | tests/tinyproxy.py: invalid syntax: Missing parentheses in call to 'print' (<unknown>, line 53) | |||
|
162 | ||||
|
163 | #endif |
General Comments 0
You need to be logged in to leave comments.
Login now