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