Show More
@@ -1,108 +1,111 b'' | |||||
1 | #!/usr/bin/env python |
|
1 | #!/usr/bin/env python | |
2 | # |
|
2 | # | |
3 | # check-config - a config flag documentation checker for Mercurial |
|
3 | # check-config - a config flag documentation checker for Mercurial | |
4 | # |
|
4 | # | |
5 | # Copyright 2015 Matt Mackall <mpm@selenic.com> |
|
5 | # Copyright 2015 Matt Mackall <mpm@selenic.com> | |
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 | import re |
|
10 | import re | |
11 | import sys |
|
11 | import sys | |
12 |
|
12 | |||
13 | foundopts = {} |
|
13 | foundopts = {} | |
14 | documented = {} |
|
14 | documented = {} | |
15 |
|
15 | |||
16 | configre = (r"""ui\.config(|int|bool|list)\(['"](\S+)['"],\s*""" |
|
16 | configre = (r"""ui\.config(|int|bool|list)\(['"](\S+)['"],\s*""" | |
17 | r"""['"](\S+)['"](,\s+(?:default=)?(\S+?))?\)""") |
|
17 | r"""['"](\S+)['"](,\s+(?:default=)?(\S+?))?\)""") | |
18 | configpartialre = (r"""ui\.config""") |
|
18 | configpartialre = (r"""ui\.config""") | |
19 |
|
19 | |||
20 | def main(args): |
|
20 | def main(args): | |
21 | for f in args: |
|
21 | for f in args: | |
22 | sect = '' |
|
22 | sect = '' | |
23 | prevname = '' |
|
23 | prevname = '' | |
24 | confsect = '' |
|
24 | confsect = '' | |
25 | carryover = '' |
|
25 | carryover = '' | |
26 | for l in open(f): |
|
26 | for l in open(f): | |
27 |
|
27 | |||
28 | # check topic-like bits |
|
28 | # check topic-like bits | |
29 | m = re.match('\s*``(\S+)``', l) |
|
29 | m = re.match('\s*``(\S+)``', l) | |
30 | if m: |
|
30 | if m: | |
31 | prevname = m.group(1) |
|
31 | prevname = m.group(1) | |
32 | if re.match('^\s*-+$', l): |
|
32 | if re.match('^\s*-+$', l): | |
33 | sect = prevname |
|
33 | sect = prevname | |
34 | prevname = '' |
|
34 | prevname = '' | |
35 |
|
35 | |||
36 | if sect and prevname: |
|
36 | if sect and prevname: | |
37 | name = sect + '.' + prevname |
|
37 | name = sect + '.' + prevname | |
38 | documented[name] = 1 |
|
38 | documented[name] = 1 | |
39 |
|
39 | |||
40 | # check docstring bits |
|
40 | # check docstring bits | |
41 | m = re.match(r'^\s+\[(\S+)\]', l) |
|
41 | m = re.match(r'^\s+\[(\S+)\]', l) | |
42 | if m: |
|
42 | if m: | |
43 | confsect = m.group(1) |
|
43 | confsect = m.group(1) | |
44 | continue |
|
44 | continue | |
45 | m = re.match(r'^\s+(?:#\s*)?(\S+) = ', l) |
|
45 | m = re.match(r'^\s+(?:#\s*)?(\S+) = ', l) | |
46 | if m: |
|
46 | if m: | |
47 | name = confsect + '.' + m.group(1) |
|
47 | name = confsect + '.' + m.group(1) | |
48 | documented[name] = 1 |
|
48 | documented[name] = 1 | |
49 |
|
49 | |||
50 | # like the bugzilla extension |
|
50 | # like the bugzilla extension | |
51 | m = re.match(r'^\s*(\S+\.\S+)$', l) |
|
51 | m = re.match(r'^\s*(\S+\.\S+)$', l) | |
52 | if m: |
|
52 | if m: | |
53 | documented[m.group(1)] = 1 |
|
53 | documented[m.group(1)] = 1 | |
54 |
|
54 | |||
55 | # like convert |
|
55 | # like convert | |
56 | m = re.match(r'^\s*:(\S+\.\S+):\s+', l) |
|
56 | m = re.match(r'^\s*:(\S+\.\S+):\s+', l) | |
57 | if m: |
|
57 | if m: | |
58 | documented[m.group(1)] = 1 |
|
58 | documented[m.group(1)] = 1 | |
59 |
|
59 | |||
60 | # quoted in help or docstrings |
|
60 | # quoted in help or docstrings | |
61 | m = re.match(r'.*?``(\S+\.\S+)``', l) |
|
61 | m = re.match(r'.*?``(\S+\.\S+)``', l) | |
62 | if m: |
|
62 | if m: | |
63 | documented[m.group(1)] = 1 |
|
63 | documented[m.group(1)] = 1 | |
64 |
|
64 | |||
65 | # look for ignore markers |
|
65 | # look for ignore markers | |
66 | m = re.search(r'# (?:internal|experimental|deprecated|developer)' |
|
66 | m = re.search(r'# (?:internal|experimental|deprecated|developer)' | |
67 | ' config: (\S+\.\S+)$', l) |
|
67 | ' config: (\S+\.\S+)$', l) | |
68 | if m: |
|
68 | if m: | |
69 | documented[m.group(1)] = 1 |
|
69 | documented[m.group(1)] = 1 | |
70 |
|
70 | |||
71 | # look for code-like bits |
|
71 | # look for code-like bits | |
72 | line = carryover + l |
|
72 | line = carryover + l | |
73 | m = re.search(configre, line, re.MULTILINE) |
|
73 | m = re.search(configre, line, re.MULTILINE) | |
74 | if m: |
|
74 | if m: | |
75 | ctype = m.group(1) |
|
75 | ctype = m.group(1) | |
76 | if not ctype: |
|
76 | if not ctype: | |
77 | ctype = 'str' |
|
77 | ctype = 'str' | |
78 | name = m.group(2) + "." + m.group(3) |
|
78 | name = m.group(2) + "." + m.group(3) | |
79 | default = m.group(5) |
|
79 | default = m.group(5) | |
80 | if default in (None, 'False', 'None', '0', '[]', '""', "''"): |
|
80 | if default in (None, 'False', 'None', '0', '[]', '""', "''"): | |
81 | default = '' |
|
81 | default = '' | |
82 | if re.match('[a-z.]+$', default): |
|
82 | if re.match('[a-z.]+$', default): | |
83 | default = '<variable>' |
|
83 | default = '<variable>' | |
84 | if name in foundopts and (ctype, default) != foundopts[name]: |
|
84 | if name in foundopts and (ctype, default) != foundopts[name]: | |
85 | print l |
|
85 | print l | |
86 | print "conflict on %s: %r != %r" % (name, (ctype, default), |
|
86 | print "conflict on %s: %r != %r" % (name, (ctype, default), | |
87 | foundopts[name]) |
|
87 | foundopts[name]) | |
88 | foundopts[name] = (ctype, default) |
|
88 | foundopts[name] = (ctype, default) | |
89 | carryover = '' |
|
89 | carryover = '' | |
90 | else: |
|
90 | else: | |
91 | m = re.search(configpartialre, line) |
|
91 | m = re.search(configpartialre, line) | |
92 | if m: |
|
92 | if m: | |
93 | carryover = line |
|
93 | carryover = line | |
94 | else: |
|
94 | else: | |
95 | carryover = '' |
|
95 | carryover = '' | |
96 |
|
96 | |||
97 | for name in sorted(foundopts): |
|
97 | for name in sorted(foundopts): | |
98 | if name not in documented: |
|
98 | if name not in documented: | |
99 | if not (name.startswith("devel.") or |
|
99 | if not (name.startswith("devel.") or | |
100 | name.startswith("experimental.") or |
|
100 | name.startswith("experimental.") or | |
101 | name.startswith("debug.")): |
|
101 | name.startswith("debug.")): | |
102 | ctype, default = foundopts[name] |
|
102 | ctype, default = foundopts[name] | |
103 | if default: |
|
103 | if default: | |
104 | default = ' [%s]' % default |
|
104 | default = ' [%s]' % default | |
105 | print "undocumented: %s (%s)%s" % (name, ctype, default) |
|
105 | print "undocumented: %s (%s)%s" % (name, ctype, default) | |
106 |
|
106 | |||
107 | if __name__ == "__main__": |
|
107 | if __name__ == "__main__": | |
108 | sys.exit(main(sys.argv[1:])) |
|
108 | if len(sys.argv) > 1: | |
|
109 | sys.exit(main(sys.argv[1:])) | |||
|
110 | else: | |||
|
111 | sys.exit(main([l.rstrip() for l in sys.stdin])) |
@@ -1,8 +1,8 b'' | |||||
1 | #require test-repo |
|
1 | #require test-repo | |
2 |
|
2 | |||
3 | $ cd "$TESTDIR"/.. |
|
3 | $ cd "$TESTDIR"/.. | |
4 |
|
4 | |||
5 | New errors are not allowed. Warnings are strongly discouraged. |
|
5 | New errors are not allowed. Warnings are strongly discouraged. | |
6 |
|
6 | |||
7 | $ hg files "set:(**.py or **.txt) - tests/**" | sed 's|\\|/|g' | |
|
7 | $ hg files "set:(**.py or **.txt) - tests/**" | sed 's|\\|/|g' | | |
8 |
> |
|
8 | > python contrib/check-config.py |
General Comments 0
You need to be logged in to leave comments.
Login now