Mercurial > hg
annotate doc/check-seclevel.py @ 49902:f3e95e5a5895 stable
convert: replace repr() by pycompat.byterepr() in cvsps.py (issue6789)
author | Anton Shestakov <av6@dwimlabs.net> |
---|---|
date | Fri, 13 Jan 2023 17:33:03 +0400 |
parents | 13dfad0f9f7a |
children | 98e7be1ed6c5 |
rev | line source |
---|---|
45830
c102b704edb5
global: use python3 in shebangs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43094
diff
changeset
|
1 #!/usr/bin/env python3 |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
2 # |
26192
67e6e55360d2
check-seclevel: fix file description grammar
timeless@mozdev.org
parents:
21792
diff
changeset
|
3 # checkseclevel - checking section title levels in each online help document |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
4 |
28965
98153441c8cc
py3: make check-seclevel use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27770
diff
changeset
|
5 |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
6 import optparse |
28965
98153441c8cc
py3: make check-seclevel use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27770
diff
changeset
|
7 import os |
98153441c8cc
py3: make check-seclevel use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27770
diff
changeset
|
8 import sys |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
9 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
10 # import from the live mercurial repo |
27221
ab776610fc6d
check-seclevel: set module load policy to Python only
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26413
diff
changeset
|
11 os.environ['HGMODULEPOLICY'] = 'py' |
49205
45e71954612c
doc: use an absolute path in sys.path
Anton Shestakov <av6@dwimlabs.net>
parents:
45830
diff
changeset
|
12 sys.path.insert(0, os.path.abspath("..")) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
13 from mercurial import demandimport |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
14 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
15 demandimport.enable() |
28965
98153441c8cc
py3: make check-seclevel use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27770
diff
changeset
|
16 from mercurial import ( |
98153441c8cc
py3: make check-seclevel use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27770
diff
changeset
|
17 commands, |
98153441c8cc
py3: make check-seclevel use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27770
diff
changeset
|
18 extensions, |
98153441c8cc
py3: make check-seclevel use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27770
diff
changeset
|
19 help, |
98153441c8cc
py3: make check-seclevel use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27770
diff
changeset
|
20 minirst, |
98153441c8cc
py3: make check-seclevel use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27770
diff
changeset
|
21 ui as uimod, |
98153441c8cc
py3: make check-seclevel use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27770
diff
changeset
|
22 ) |
98153441c8cc
py3: make check-seclevel use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27770
diff
changeset
|
23 |
98153441c8cc
py3: make check-seclevel use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27770
diff
changeset
|
24 table = commands.table |
98153441c8cc
py3: make check-seclevel use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27770
diff
changeset
|
25 helptable = help.helptable |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
26 |
32544
e9f456183402
doc: port check-seclevel.py to be Python 2/3 portable
Augie Fackler <raf@durin42.com>
parents:
30559
diff
changeset
|
27 level2mark = [b'"', b'=', b'-', b'.', b'#'] |
e9f456183402
doc: port check-seclevel.py to be Python 2/3 portable
Augie Fackler <raf@durin42.com>
parents:
30559
diff
changeset
|
28 reservedmarks = [b'"'] |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
29 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
30 mark2level = {} |
32544
e9f456183402
doc: port check-seclevel.py to be Python 2/3 portable
Augie Fackler <raf@durin42.com>
parents:
30559
diff
changeset
|
31 for m, l in zip(level2mark, range(len(level2mark))): |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
32 if m not in reservedmarks: |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
33 mark2level[m] = l |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
34 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
35 initlevel_topic = 0 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
36 initlevel_cmd = 1 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
37 initlevel_ext = 1 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
38 initlevel_ext_cmd = 3 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
39 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
40 |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
41 def showavailables(ui, initlevel): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
42 avail = ' available marks and order of them in this help: %s\n' % ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
43 ', '.join(['%r' % (m * 4) for m in level2mark[initlevel + 1 :]]) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
44 ) |
32544
e9f456183402
doc: port check-seclevel.py to be Python 2/3 portable
Augie Fackler <raf@durin42.com>
parents:
30559
diff
changeset
|
45 ui.warn(avail.encode('utf-8')) |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
46 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
47 |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
48 def checkseclevel(ui, doc, name, initlevel): |
43080
86e4daa2d54c
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
49 ui.notenoi18n('checking "%s"\n' % name) |
32544
e9f456183402
doc: port check-seclevel.py to be Python 2/3 portable
Augie Fackler <raf@durin42.com>
parents:
30559
diff
changeset
|
50 if not isinstance(doc, bytes): |
e9f456183402
doc: port check-seclevel.py to be Python 2/3 portable
Augie Fackler <raf@durin42.com>
parents:
30559
diff
changeset
|
51 doc = doc.encode('utf-8') |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
52 blocks, pruned = minirst.parse(doc, 0, ['verbose']) |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
53 errorcnt = 0 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
54 curlevel = initlevel |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
55 for block in blocks: |
32544
e9f456183402
doc: port check-seclevel.py to be Python 2/3 portable
Augie Fackler <raf@durin42.com>
parents:
30559
diff
changeset
|
56 if block[b'type'] != b'section': |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
57 continue |
32544
e9f456183402
doc: port check-seclevel.py to be Python 2/3 portable
Augie Fackler <raf@durin42.com>
parents:
30559
diff
changeset
|
58 mark = block[b'underline'] |
e9f456183402
doc: port check-seclevel.py to be Python 2/3 portable
Augie Fackler <raf@durin42.com>
parents:
30559
diff
changeset
|
59 title = block[b'lines'][0] |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
60 if (mark not in mark2level) or (mark2level[mark] <= initlevel): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
61 ui.warn( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
62 ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
63 'invalid section mark %r for "%s" of %s\n' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
64 % (mark * 4, title, name) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
65 ).encode('utf-8') |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
66 ) |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
67 showavailables(ui, initlevel) |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
68 errorcnt += 1 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
69 continue |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
70 nextlevel = mark2level[mark] |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
71 if curlevel < nextlevel and curlevel + 1 != nextlevel: |
43094
e8cf9ad52a78
formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43080
diff
changeset
|
72 ui.warnnoi18n( |
e8cf9ad52a78
formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43080
diff
changeset
|
73 'gap of section level at "%s" of %s\n' % (title, name) |
e8cf9ad52a78
formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43080
diff
changeset
|
74 ) |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
75 showavailables(ui, initlevel) |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
76 errorcnt += 1 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
77 continue |
43080
86e4daa2d54c
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
78 ui.notenoi18n( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
79 'appropriate section level for "%s %s"\n' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
80 % (mark * (nextlevel * 2), title) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
81 ) |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
82 curlevel = nextlevel |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
83 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
84 return errorcnt |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
85 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
86 |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
87 def checkcmdtable(ui, cmdtable, namefmt, initlevel): |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
88 errorcnt = 0 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
89 for k, entry in cmdtable.items(): |
32544
e9f456183402
doc: port check-seclevel.py to be Python 2/3 portable
Augie Fackler <raf@durin42.com>
parents:
30559
diff
changeset
|
90 name = k.split(b"|")[0].lstrip(b"^") |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
91 if not entry[0].__doc__: |
43094
e8cf9ad52a78
formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43080
diff
changeset
|
92 ui.notenoi18n( |
e8cf9ad52a78
formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43080
diff
changeset
|
93 'skip checking %s: no help document\n' % (namefmt % name) |
e8cf9ad52a78
formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43080
diff
changeset
|
94 ) |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
95 continue |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
96 errorcnt += checkseclevel( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
97 ui, entry[0].__doc__, namefmt % name, initlevel |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
98 ) |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
99 return errorcnt |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
100 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
101 |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
102 def checkhghelps(ui): |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
103 errorcnt = 0 |
40292
9c6473d2038b
help: splitting the topics by category
Rodrigo Damazio <rdamazio@google.com>
parents:
32544
diff
changeset
|
104 for h in helptable: |
9c6473d2038b
help: splitting the topics by category
Rodrigo Damazio <rdamazio@google.com>
parents:
32544
diff
changeset
|
105 names, sec, doc = h[0:3] |
21792
e15c991fe2ec
check-seclevel: restore use of callable() since it was readded in Python 3.2
Augie Fackler <raf@durin42.com>
parents:
17648
diff
changeset
|
106 if callable(doc): |
26413
e0c572d4d112
help: pass around ui to doc loader (API)
Yuya Nishihara <yuya@tcha.org>
parents:
26411
diff
changeset
|
107 doc = doc(ui) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
108 errorcnt += checkseclevel( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
109 ui, doc, '%s help topic' % names[0], initlevel_topic |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
110 ) |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
111 |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
112 errorcnt += checkcmdtable(ui, table, '%s command', initlevel_cmd) |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
113 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
114 for name in sorted( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
115 list(extensions.enabled()) + list(extensions.disabled()) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
116 ): |
27511
44a596a8bed1
check-seclevel: pass a ui to the extension loader
Bryan O'Sullivan <bos@serpentine.com>
parents:
27510
diff
changeset
|
117 mod = extensions.load(ui, name, None) |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
118 if not mod.__doc__: |
43094
e8cf9ad52a78
formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43080
diff
changeset
|
119 ui.notenoi18n( |
e8cf9ad52a78
formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43080
diff
changeset
|
120 'skip checking %s extension: no help document\n' % name |
e8cf9ad52a78
formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43080
diff
changeset
|
121 ) |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
122 continue |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
123 errorcnt += checkseclevel( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
124 ui, mod.__doc__, '%s extension' % name, initlevel_ext |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
125 ) |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
126 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
127 cmdtable = getattr(mod, 'cmdtable', None) |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
128 if cmdtable: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
129 errorcnt += checkcmdtable( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
130 ui, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
131 cmdtable, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
132 '%%s command of %s extension' % name, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
133 initlevel_ext_cmd, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
134 ) |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
135 return errorcnt |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
136 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
137 |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
138 def checkfile(ui, filename, initlevel): |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
139 if filename == '-': |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
140 filename = 'stdin' |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
141 doc = sys.stdin.read() |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
142 else: |
27770
1b8c7d59be43
check-seclevel: use a context manager for file I/O
Bryan O'Sullivan <bryano@fb.com>
parents:
27511
diff
changeset
|
143 with open(filename) as fp: |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
144 doc = fp.read() |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
145 |
43080
86e4daa2d54c
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
146 ui.notenoi18n( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
147 'checking input from %s with initlevel %d\n' % (filename, initlevel) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
148 ) |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
149 return checkseclevel(ui, doc, 'input from %s' % filename, initlevel) |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
150 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
151 |
26398
70abba798098
check-seclevel: wrap entry point by function
Yuya Nishihara <yuya@tcha.org>
parents:
26192
diff
changeset
|
152 def main(): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
153 optparser = optparse.OptionParser( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
154 """%prog [options] |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
155 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
156 This checks all help documents of Mercurial (topics, commands, |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
157 extensions and commands of them), if no file is specified by --file |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
158 option. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
159 """ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
160 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
161 optparser.add_option( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
162 "-v", "--verbose", help="enable additional output", action="store_true" |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
163 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
164 optparser.add_option( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
165 "-d", "--debug", help="debug mode", action="store_true" |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
166 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
167 optparser.add_option( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
168 "-f", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
169 "--file", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
170 help="filename to read in (or '-' for stdin)", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
171 action="store", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
172 default="", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
173 ) |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
174 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
175 optparser.add_option( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
176 "-t", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
177 "--topic", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
178 help="parse file as help topic", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
179 action="store_const", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
180 dest="initlevel", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
181 const=0, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
182 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
183 optparser.add_option( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
184 "-c", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
185 "--command", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
186 help="parse file as help of core command", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
187 action="store_const", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
188 dest="initlevel", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
189 const=1, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
190 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
191 optparser.add_option( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
192 "-e", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
193 "--extension", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
194 help="parse file as help of extension", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
195 action="store_const", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
196 dest="initlevel", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
197 const=1, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
198 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
199 optparser.add_option( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
200 "-C", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
201 "--extension-command", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
202 help="parse file as help of extension command", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
203 action="store_const", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
204 dest="initlevel", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
205 const=3, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
206 ) |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
207 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
208 optparser.add_option( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
209 "-l", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
210 "--initlevel", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
211 help="set initial section level manually", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
212 action="store", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
213 type="int", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
214 default=0, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
215 ) |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
216 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
217 (options, args) = optparser.parse_args() |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
218 |
30559
d83ca854fa21
ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents:
28965
diff
changeset
|
219 ui = uimod.ui.load() |
41355
77763dc5b07b
py3: add b'' prefixes in doc/check-seclevel.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
40292
diff
changeset
|
220 ui.setconfig(b'ui', b'verbose', options.verbose, b'--verbose') |
77763dc5b07b
py3: add b'' prefixes in doc/check-seclevel.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
40292
diff
changeset
|
221 ui.setconfig(b'ui', b'debug', options.debug, b'--debug') |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
222 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
223 if options.file: |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
224 if checkfile(ui, options.file, options.initlevel): |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
225 sys.exit(1) |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
226 else: |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
227 if checkhghelps(ui): |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
228 sys.exit(1) |
26398
70abba798098
check-seclevel: wrap entry point by function
Yuya Nishihara <yuya@tcha.org>
parents:
26192
diff
changeset
|
229 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
230 |
26398
70abba798098
check-seclevel: wrap entry point by function
Yuya Nishihara <yuya@tcha.org>
parents:
26192
diff
changeset
|
231 if __name__ == "__main__": |
70abba798098
check-seclevel: wrap entry point by function
Yuya Nishihara <yuya@tcha.org>
parents:
26192
diff
changeset
|
232 main() |