Mercurial > hg
annotate doc/check-seclevel.py @ 50269:05de4896508e stable 6.4rc0
branching: merge default into stable
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Thu, 02 Mar 2023 22:45:44 +0100 |
parents | 98e7be1ed6c5 |
children |
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): |
49796
98e7be1ed6c5
doc: don't pass str to ui methods in check-seclevel.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49217
diff
changeset
|
49 ui.notenoi18n(('checking "%s"\n' % name).encode('utf-8')) |
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( |
49796
98e7be1ed6c5
doc: don't pass str to ui methods in check-seclevel.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49217
diff
changeset
|
73 ('gap of section level at "%s" of %s\n' % (title, name)).encode( |
98e7be1ed6c5
doc: don't pass str to ui methods in check-seclevel.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49217
diff
changeset
|
74 'utf-8' |
98e7be1ed6c5
doc: don't pass str to ui methods in check-seclevel.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49217
diff
changeset
|
75 ) |
43094
e8cf9ad52a78
formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43080
diff
changeset
|
76 ) |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
77 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
|
78 errorcnt += 1 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
79 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
|
80 ui.notenoi18n( |
49796
98e7be1ed6c5
doc: don't pass str to ui methods in check-seclevel.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49217
diff
changeset
|
81 ( |
98e7be1ed6c5
doc: don't pass str to ui methods in check-seclevel.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49217
diff
changeset
|
82 'appropriate section level for "%s %s"\n' |
98e7be1ed6c5
doc: don't pass str to ui methods in check-seclevel.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49217
diff
changeset
|
83 % (mark * (nextlevel * 2), title) |
98e7be1ed6c5
doc: don't pass str to ui methods in check-seclevel.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49217
diff
changeset
|
84 ).encode('utf-8') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
85 ) |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
86 curlevel = nextlevel |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
87 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
88 return errorcnt |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
89 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
90 |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
91 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
|
92 errorcnt = 0 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
93 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
|
94 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
|
95 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
|
96 ui.notenoi18n( |
49796
98e7be1ed6c5
doc: don't pass str to ui methods in check-seclevel.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49217
diff
changeset
|
97 ( |
98e7be1ed6c5
doc: don't pass str to ui methods in check-seclevel.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49217
diff
changeset
|
98 'skip checking %s: no help document\n' % (namefmt % name) |
98e7be1ed6c5
doc: don't pass str to ui methods in check-seclevel.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49217
diff
changeset
|
99 ).encode('utf-8') |
43094
e8cf9ad52a78
formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43080
diff
changeset
|
100 ) |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
101 continue |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
102 errorcnt += checkseclevel( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
103 ui, entry[0].__doc__, namefmt % name, initlevel |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
104 ) |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
105 return errorcnt |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
106 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
107 |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
108 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
|
109 errorcnt = 0 |
40292
9c6473d2038b
help: splitting the topics by category
Rodrigo Damazio <rdamazio@google.com>
parents:
32544
diff
changeset
|
110 for h in helptable: |
9c6473d2038b
help: splitting the topics by category
Rodrigo Damazio <rdamazio@google.com>
parents:
32544
diff
changeset
|
111 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
|
112 if callable(doc): |
26413
e0c572d4d112
help: pass around ui to doc loader (API)
Yuya Nishihara <yuya@tcha.org>
parents:
26411
diff
changeset
|
113 doc = doc(ui) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
114 errorcnt += checkseclevel( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
115 ui, doc, '%s help topic' % names[0], initlevel_topic |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
116 ) |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
117 |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
118 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
|
119 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
120 for name in sorted( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
121 list(extensions.enabled()) + list(extensions.disabled()) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
122 ): |
27511
44a596a8bed1
check-seclevel: pass a ui to the extension loader
Bryan O'Sullivan <bos@serpentine.com>
parents:
27510
diff
changeset
|
123 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
|
124 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
|
125 ui.notenoi18n( |
49796
98e7be1ed6c5
doc: don't pass str to ui methods in check-seclevel.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49217
diff
changeset
|
126 ( |
98e7be1ed6c5
doc: don't pass str to ui methods in check-seclevel.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49217
diff
changeset
|
127 'skip checking %s extension: no help document\n' % name |
98e7be1ed6c5
doc: don't pass str to ui methods in check-seclevel.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49217
diff
changeset
|
128 ).encode('utf-8') |
43094
e8cf9ad52a78
formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43080
diff
changeset
|
129 ) |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
130 continue |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
131 errorcnt += checkseclevel( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
132 ui, mod.__doc__, '%s extension' % name, initlevel_ext |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
133 ) |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
134 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
135 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
|
136 if cmdtable: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
137 errorcnt += checkcmdtable( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
138 ui, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
139 cmdtable, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
140 '%%s command of %s extension' % name, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
141 initlevel_ext_cmd, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
142 ) |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
143 return errorcnt |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
144 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
145 |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
146 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
|
147 if filename == '-': |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
148 filename = 'stdin' |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
149 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
|
150 else: |
27770
1b8c7d59be43
check-seclevel: use a context manager for file I/O
Bryan O'Sullivan <bryano@fb.com>
parents:
27511
diff
changeset
|
151 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
|
152 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
|
153 |
43080
86e4daa2d54c
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
154 ui.notenoi18n( |
49796
98e7be1ed6c5
doc: don't pass str to ui methods in check-seclevel.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49217
diff
changeset
|
155 ( |
98e7be1ed6c5
doc: don't pass str to ui methods in check-seclevel.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49217
diff
changeset
|
156 'checking input from %s with initlevel %d\n' % (filename, initlevel) |
98e7be1ed6c5
doc: don't pass str to ui methods in check-seclevel.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
49217
diff
changeset
|
157 ).encode('utf-8') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
158 ) |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
159 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
|
160 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
161 |
26398
70abba798098
check-seclevel: wrap entry point by function
Yuya Nishihara <yuya@tcha.org>
parents:
26192
diff
changeset
|
162 def main(): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
163 optparser = optparse.OptionParser( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
164 """%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
|
165 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
166 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
|
167 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
|
168 option. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
169 """ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
170 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
171 optparser.add_option( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
172 "-v", "--verbose", help="enable additional output", action="store_true" |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
173 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
174 optparser.add_option( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
175 "-d", "--debug", help="debug mode", action="store_true" |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
176 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
177 optparser.add_option( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
178 "-f", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
179 "--file", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
180 help="filename to read in (or '-' for stdin)", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
181 action="store", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
182 default="", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
183 ) |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
184 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
185 optparser.add_option( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
186 "-t", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
187 "--topic", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
188 help="parse file as help topic", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
189 action="store_const", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
190 dest="initlevel", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
191 const=0, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
192 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
193 optparser.add_option( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
194 "-c", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
195 "--command", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
196 help="parse file as help of core command", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
197 action="store_const", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
198 dest="initlevel", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
199 const=1, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
200 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
201 optparser.add_option( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
202 "-e", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
203 "--extension", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
204 help="parse file as help of extension", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
205 action="store_const", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
206 dest="initlevel", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
207 const=1, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
208 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
209 optparser.add_option( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
210 "-C", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
211 "--extension-command", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
212 help="parse file as help of extension command", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
213 action="store_const", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
214 dest="initlevel", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
215 const=3, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
216 ) |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
217 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
218 optparser.add_option( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
219 "-l", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
220 "--initlevel", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
221 help="set initial section level manually", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
222 action="store", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
223 type="int", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
224 default=0, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
225 ) |
17648
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
226 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
227 (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
|
228 |
30559
d83ca854fa21
ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents:
28965
diff
changeset
|
229 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
|
230 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
|
231 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
|
232 |
07f1ac17b722
doc: add the tool to check section marks in help documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
233 if options.file: |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
234 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
|
235 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
|
236 else: |
26411
dd62eaa82cbe
check-seclevel: use ui to show status and error messages
Yuya Nishihara <yuya@tcha.org>
parents:
26398
diff
changeset
|
237 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
|
238 sys.exit(1) |
26398
70abba798098
check-seclevel: wrap entry point by function
Yuya Nishihara <yuya@tcha.org>
parents:
26192
diff
changeset
|
239 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41355
diff
changeset
|
240 |
26398
70abba798098
check-seclevel: wrap entry point by function
Yuya Nishihara <yuya@tcha.org>
parents:
26192
diff
changeset
|
241 if __name__ == "__main__": |
70abba798098
check-seclevel: wrap entry point by function
Yuya Nishihara <yuya@tcha.org>
parents:
26192
diff
changeset
|
242 main() |