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