##// END OF EJS Templates
py3: make doc/docchecker use print_function
Pulkit Goyal -
r29169:c9ab5a0b default
parent child Browse files
Show More
@@ -1,66 +1,66
1 #!/usr/bin/env python
1 #!/usr/bin/env python
2 #
2 #
3 # docchecker - look for problematic markup
3 # docchecker - look for problematic markup
4 #
4 #
5 # Copyright 2016 timeless <timeless@mozdev.org> and others
5 # Copyright 2016 timeless <timeless@mozdev.org> and others
6 #
6 #
7 # This software may be used and distributed according to the terms of the
7 # This software may be used and distributed according to the terms of the
8 # GNU General Public License version 2 or any later version.
8 # GNU General Public License version 2 or any later version.
9
9
10 from __future__ import absolute_import
10 from __future__ import absolute_import, print_function
11
11
12 import re
12 import re
13 import sys
13 import sys
14
14
15 leadingline = re.compile(r'(^\s*)(\S.*)$')
15 leadingline = re.compile(r'(^\s*)(\S.*)$')
16
16
17 checks = [
17 checks = [
18 (r""":hg:`[^`]*'[^`]*`""",
18 (r""":hg:`[^`]*'[^`]*`""",
19 """warning: please avoid nesting ' in :hg:`...`"""),
19 """warning: please avoid nesting ' in :hg:`...`"""),
20 (r'\w:hg:`',
20 (r'\w:hg:`',
21 'warning: please have a space before :hg:'),
21 'warning: please have a space before :hg:'),
22 (r"""(?:[^a-z][^'.])hg ([^,;"`]*'(?!hg)){2}""",
22 (r"""(?:[^a-z][^'.])hg ([^,;"`]*'(?!hg)){2}""",
23 '''warning: please use " instead of ' for hg ... "..."'''),
23 '''warning: please use " instead of ' for hg ... "..."'''),
24 ]
24 ]
25
25
26 def check(line):
26 def check(line):
27 messages = []
27 messages = []
28 for match, msg in checks:
28 for match, msg in checks:
29 if re.search(match, line):
29 if re.search(match, line):
30 messages.append(msg)
30 messages.append(msg)
31 if messages:
31 if messages:
32 print(line)
32 print(line)
33 for msg in messages:
33 for msg in messages:
34 print(msg)
34 print(msg)
35
35
36 def work(file):
36 def work(file):
37 (llead, lline) = ('', '')
37 (llead, lline) = ('', '')
38
38
39 for line in file:
39 for line in file:
40 # this section unwraps lines
40 # this section unwraps lines
41 match = leadingline.match(line)
41 match = leadingline.match(line)
42 if not match:
42 if not match:
43 check(lline)
43 check(lline)
44 (llead, lline) = ('', '')
44 (llead, lline) = ('', '')
45 continue
45 continue
46
46
47 lead, line = match.group(1), match.group(2)
47 lead, line = match.group(1), match.group(2)
48 if (lead == llead):
48 if (lead == llead):
49 if (lline != ''):
49 if (lline != ''):
50 lline += ' ' + line
50 lline += ' ' + line
51 else:
51 else:
52 lline = line
52 lline = line
53 else:
53 else:
54 check(lline)
54 check(lline)
55 (llead, lline) = (lead, line)
55 (llead, lline) = (lead, line)
56 check(lline)
56 check(lline)
57
57
58 def main():
58 def main():
59 for f in sys.argv[1:]:
59 for f in sys.argv[1:]:
60 try:
60 try:
61 with open(f) as file:
61 with open(f) as file:
62 work(file)
62 work(file)
63 except BaseException as e:
63 except BaseException as e:
64 print("failed to process %s: %s" % (f, e))
64 print("failed to process %s: %s" % (f, e))
65
65
66 main()
66 main()
General Comments 0
You need to be logged in to leave comments. Login now