##// END OF EJS Templates
tests: perform an ast parse with Python 3...
Gregory Szorc -
r28583:260ce2ee default
parent child Browse files
Show More
@@ -1,43 +1,59 b''
1 1 #!/usr/bin/env python
2 2 #
3 3 # check-py3-compat - check Python 3 compatibility of Mercurial files
4 4 #
5 5 # Copyright 2015 Gregory Szorc <gregory.szorc@gmail.com>
6 6 #
7 7 # This software may be used and distributed according to the terms of the
8 8 # GNU General Public License version 2 or any later version.
9 9
10 10 from __future__ import absolute_import, print_function
11 11
12 12 import ast
13 13 import sys
14 14
15 def check_compat(f):
16 """Check Python 3 compatibility for a file."""
15 def check_compat_py2(f):
16 """Check Python 3 compatibility for a file with Python 2"""
17 17 with open(f, 'rb') as fh:
18 18 content = fh.read()
19 19 root = ast.parse(content)
20 20
21 21 # Ignore empty files.
22 22 if not root.body:
23 23 return
24 24
25 25 futures = set()
26 26 haveprint = False
27 27 for node in ast.walk(root):
28 28 if isinstance(node, ast.ImportFrom):
29 29 if node.module == '__future__':
30 30 futures |= set(n.name for n in node.names)
31 31 elif isinstance(node, ast.Print):
32 32 haveprint = True
33 33
34 34 if 'absolute_import' not in futures:
35 35 print('%s not using absolute_import' % f)
36 36 if haveprint and 'print_function' not in futures:
37 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 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 56 for f in sys.argv[1:]:
41 check_compat(f)
57 fn(f)
42 58
43 59 sys.exit(0)
@@ -1,120 +1,163 b''
1 1 #require test-repo
2 2
3 3 $ cd "$TESTDIR"/..
4 4
5 5 $ hg files 'set:(**.py)' | sed 's|\\|/|g' | xargs python contrib/check-py3-compat.py
6 6 contrib/import-checker.py not using absolute_import
7 7 contrib/import-checker.py requires print_function
8 8 doc/check-seclevel.py not using absolute_import
9 9 doc/gendoc.py not using absolute_import
10 10 doc/hgmanpage.py not using absolute_import
11 11 hgext/color.py not using absolute_import
12 12 hgext/eol.py not using absolute_import
13 13 hgext/extdiff.py not using absolute_import
14 14 hgext/factotum.py not using absolute_import
15 15 hgext/fetch.py not using absolute_import
16 16 hgext/fsmonitor/pywatchman/__init__.py not using absolute_import
17 17 hgext/fsmonitor/pywatchman/__init__.py requires print_function
18 18 hgext/fsmonitor/pywatchman/capabilities.py not using absolute_import
19 19 hgext/fsmonitor/pywatchman/pybser.py not using absolute_import
20 20 hgext/gpg.py not using absolute_import
21 21 hgext/graphlog.py not using absolute_import
22 22 hgext/hgcia.py not using absolute_import
23 23 hgext/hgk.py not using absolute_import
24 24 hgext/highlight/__init__.py not using absolute_import
25 25 hgext/highlight/highlight.py not using absolute_import
26 26 hgext/histedit.py not using absolute_import
27 27 hgext/largefiles/__init__.py not using absolute_import
28 28 hgext/largefiles/basestore.py not using absolute_import
29 29 hgext/largefiles/lfcommands.py not using absolute_import
30 30 hgext/largefiles/lfutil.py not using absolute_import
31 31 hgext/largefiles/localstore.py not using absolute_import
32 32 hgext/largefiles/overrides.py not using absolute_import
33 33 hgext/largefiles/proto.py not using absolute_import
34 34 hgext/largefiles/remotestore.py not using absolute_import
35 35 hgext/largefiles/reposetup.py not using absolute_import
36 36 hgext/largefiles/uisetup.py not using absolute_import
37 37 hgext/largefiles/wirestore.py not using absolute_import
38 38 hgext/mq.py not using absolute_import
39 39 hgext/rebase.py not using absolute_import
40 40 hgext/share.py not using absolute_import
41 41 hgext/win32text.py not using absolute_import
42 42 i18n/check-translation.py not using absolute_import
43 43 i18n/polib.py not using absolute_import
44 44 setup.py not using absolute_import
45 45 tests/filterpyflakes.py requires print_function
46 46 tests/generate-working-copy-states.py requires print_function
47 47 tests/get-with-headers.py requires print_function
48 48 tests/heredoctest.py requires print_function
49 49 tests/hypothesishelpers.py not using absolute_import
50 50 tests/hypothesishelpers.py requires print_function
51 51 tests/killdaemons.py not using absolute_import
52 52 tests/md5sum.py not using absolute_import
53 53 tests/mockblackbox.py not using absolute_import
54 54 tests/printenv.py not using absolute_import
55 55 tests/readlink.py not using absolute_import
56 56 tests/readlink.py requires print_function
57 57 tests/revlog-formatv0.py not using absolute_import
58 58 tests/run-tests.py not using absolute_import
59 59 tests/seq.py not using absolute_import
60 60 tests/seq.py requires print_function
61 61 tests/silenttestrunner.py not using absolute_import
62 62 tests/silenttestrunner.py requires print_function
63 63 tests/sitecustomize.py not using absolute_import
64 64 tests/svn-safe-append.py not using absolute_import
65 65 tests/svnxml.py not using absolute_import
66 66 tests/test-ancestor.py requires print_function
67 67 tests/test-atomictempfile.py not using absolute_import
68 68 tests/test-batching.py not using absolute_import
69 69 tests/test-batching.py requires print_function
70 70 tests/test-bdiff.py not using absolute_import
71 71 tests/test-bdiff.py requires print_function
72 72 tests/test-context.py not using absolute_import
73 73 tests/test-context.py requires print_function
74 74 tests/test-demandimport.py not using absolute_import
75 75 tests/test-demandimport.py requires print_function
76 76 tests/test-doctest.py not using absolute_import
77 77 tests/test-duplicateoptions.py not using absolute_import
78 78 tests/test-duplicateoptions.py requires print_function
79 79 tests/test-filecache.py not using absolute_import
80 80 tests/test-filecache.py requires print_function
81 81 tests/test-filelog.py not using absolute_import
82 82 tests/test-filelog.py requires print_function
83 83 tests/test-hg-parseurl.py not using absolute_import
84 84 tests/test-hg-parseurl.py requires print_function
85 85 tests/test-hgweb-auth.py not using absolute_import
86 86 tests/test-hgweb-auth.py requires print_function
87 87 tests/test-hgwebdir-paths.py not using absolute_import
88 88 tests/test-hybridencode.py not using absolute_import
89 89 tests/test-hybridencode.py requires print_function
90 90 tests/test-lrucachedict.py not using absolute_import
91 91 tests/test-lrucachedict.py requires print_function
92 92 tests/test-manifest.py not using absolute_import
93 93 tests/test-minirst.py not using absolute_import
94 94 tests/test-minirst.py requires print_function
95 95 tests/test-parseindex2.py not using absolute_import
96 96 tests/test-parseindex2.py requires print_function
97 97 tests/test-pathencode.py not using absolute_import
98 98 tests/test-pathencode.py requires print_function
99 99 tests/test-propertycache.py not using absolute_import
100 100 tests/test-propertycache.py requires print_function
101 101 tests/test-revlog-ancestry.py not using absolute_import
102 102 tests/test-revlog-ancestry.py requires print_function
103 103 tests/test-run-tests.py not using absolute_import
104 104 tests/test-simplemerge.py not using absolute_import
105 105 tests/test-status-inprocess.py not using absolute_import
106 106 tests/test-status-inprocess.py requires print_function
107 107 tests/test-symlink-os-yes-fs-no.py not using absolute_import
108 108 tests/test-trusted.py not using absolute_import
109 109 tests/test-trusted.py requires print_function
110 110 tests/test-ui-color.py not using absolute_import
111 111 tests/test-ui-color.py requires print_function
112 112 tests/test-ui-config.py not using absolute_import
113 113 tests/test-ui-config.py requires print_function
114 114 tests/test-ui-verbosity.py not using absolute_import
115 115 tests/test-ui-verbosity.py requires print_function
116 116 tests/test-url.py not using absolute_import
117 117 tests/test-url.py requires print_function
118 118 tests/test-walkrepo.py requires print_function
119 119 tests/test-wireproto.py requires print_function
120 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