Skip to content

Commit 485f6f7

Browse files
mchehabJonathan Corbet
authored andcommitted
scripts/kernel-doc.py: adjust some coding style issues
Make pylint happier by adding some missing documentation and addressing a couple of pylint warnings. Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org> Signed-off-by: Jonathan Corbet <corbet@lwn.net> Link: https://lore.kernel.org/r/0f9d5473105e4c09c6c41e3db72cc63f1d4d55f9.1744106242.git.mchehab+huawei@kernel.org
1 parent 43ecfe6 commit 485f6f7

5 files changed

Lines changed: 57 additions & 42 deletions

File tree

scripts/kernel-doc.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# SPDX-License-Identifier: GPL-2.0
33
# Copyright(c) 2025: Mauro Carvalho Chehab <mchehab@kernel.org>.
44
#
5-
# pylint: disable=C0103
5+
# pylint: disable=C0103,R0915
66
#
77
# Converted from the kernel-doc script originally written in Perl
88
# under GPLv2, copyrighted since 1998 by the following authors:
@@ -165,6 +165,8 @@
165165

166166

167167
class MsgFormatter(logging.Formatter):
168+
"""Helper class to format warnings on a similar way to kernel-doc.pl"""
169+
168170
def format(self, record):
169171
record.levelname = record.levelname.capitalize()
170172
return logging.Formatter.format(self, record)
@@ -241,7 +243,7 @@ def main():
241243

242244
# Those are valid for all 3 types of filter
243245
parser.add_argument("-n", "-nosymbol", "--nosymbol", action='append',
244-
help=NOSYMBOL_DESC)
246+
help=NOSYMBOL_DESC)
245247

246248
parser.add_argument("-D", "-no-doc-sections", "--no-doc-sections",
247249
action='store_true', help="Don't outputt DOC sections")
@@ -286,9 +288,9 @@ def main():
286288
kfiles.parse(args.files, export_file=args.export_file)
287289

288290
for t in kfiles.msg(enable_lineno=args.enable_lineno, export=args.export,
289-
internal=args.internal, symbol=args.symbol,
290-
nosymbol=args.nosymbol,
291-
no_doc_sections=args.no_doc_sections):
291+
internal=args.internal, symbol=args.symbol,
292+
nosymbol=args.nosymbol,
293+
no_doc_sections=args.no_doc_sections):
292294
msg = t[1]
293295
if msg:
294296
print(msg)

scripts/lib/kdoc/kdoc_files.py

100755100644
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
#
55
# pylint: disable=R0903,R0913,R0914,R0917
66

7-
# TODO: implement warning filtering
8-
97
"""
108
Parse lernel-doc tags on multiple kernel source files.
119
"""
@@ -128,7 +126,7 @@ def file_not_found_cb(self, fname):
128126
def __init__(self, verbose=False, out_style=None,
129127
werror=False, wreturn=False, wshort_desc=False,
130128
wcontents_before_sections=False,
131-
logger=None, modulename=None, export_file=None):
129+
logger=None, modulename=None):
132130
"""
133131
Initialize startup variables and parse all files
134132
"""

scripts/lib/kdoc/kdoc_output.py

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
# SPDX-License-Identifier: GPL-2.0
33
# Copyright(c) 2025: Mauro Carvalho Chehab <mchehab@kernel.org>.
44
#
5-
# pylint: disable=C0301,R0911,R0912,R0913,R0914,R0915,R0917
6-
7-
# TODO: implement warning filtering
5+
# pylint: disable=C0301,R0902,R0911,R0912,R0913,R0914,R0915,R0917
86

97
"""
108
Implement output filters to print kernel-doc documentation.
@@ -52,6 +50,11 @@
5250

5351

5452
class OutputFormat:
53+
"""
54+
Base class for OutputFormat. If used as-is, it means that only
55+
warnings will be displayed.
56+
"""
57+
5558
# output mode.
5659
OUTPUT_ALL = 0 # output all symbols and doc sections
5760
OUTPUT_INCLUDE = 1 # output only specified symbols
@@ -75,6 +78,10 @@ def __init__(self):
7578
self.data = ""
7679

7780
def set_config(self, config):
81+
"""
82+
Setup global config variables used by both parser and output.
83+
"""
84+
7885
self.config = config
7986

8087
def set_filter(self, export, internal, symbol, nosymbol, function_table,
@@ -117,6 +124,10 @@ def highlight_block(self, block):
117124
return block
118125

119126
def out_warnings(self, args):
127+
"""
128+
Output warnings for identifiers that will be displayed.
129+
"""
130+
120131
warnings = args.get('warnings', [])
121132

122133
for warning, log_msg in warnings:
@@ -146,6 +157,11 @@ def check_doc(self, name, args):
146157
return False
147158

148159
def check_declaration(self, dtype, name, args):
160+
"""
161+
Checks if a declaration should be output or not based on the
162+
filtering criteria.
163+
"""
164+
149165
if name in self.nosymbol:
150166
return False
151167

@@ -169,6 +185,10 @@ def check_declaration(self, dtype, name, args):
169185
return False
170186

171187
def msg(self, fname, name, args):
188+
"""
189+
Handles a single entry from kernel-doc parser
190+
"""
191+
172192
self.data = ""
173193

174194
dtype = args.get('type', "")
@@ -203,24 +223,25 @@ def msg(self, fname, name, args):
203223
return None
204224

205225
# Virtual methods to be overridden by inherited classes
226+
# At the base class, those do nothing.
206227
def out_doc(self, fname, name, args):
207-
pass
228+
"""Outputs a DOC block"""
208229

209230
def out_function(self, fname, name, args):
210-
pass
231+
"""Outputs a function"""
211232

212233
def out_enum(self, fname, name, args):
213-
pass
234+
"""Outputs an enum"""
214235

215236
def out_typedef(self, fname, name, args):
216-
pass
237+
"""Outputs a typedef"""
217238

218239
def out_struct(self, fname, name, args):
219-
pass
240+
"""Outputs a struct"""
220241

221242

222243
class RestFormat(OutputFormat):
223-
# """Consts and functions used by ReST output"""
244+
"""Consts and functions used by ReST output"""
224245

225246
highlights = [
226247
(type_constant, r"``\1``"),
@@ -265,6 +286,11 @@ def print_lineno(self, ln):
265286
self.data += f".. LINENO {ln}\n"
266287

267288
def output_highlight(self, args):
289+
"""
290+
Outputs a C symbol that may require being converted to ReST using
291+
the self.highlights variable
292+
"""
293+
268294
input_text = args
269295
output = ""
270296
in_literal = False
@@ -579,6 +605,10 @@ def __init__(self):
579605
self.man_date = dt.strftime("%B %Y")
580606

581607
def output_highlight(self, block):
608+
"""
609+
Outputs a C symbol that may require being highlighted with
610+
self.highlights variable using troff syntax
611+
"""
582612

583613
contents = self.highlight_block(block)
584614

@@ -601,7 +631,7 @@ def out_doc(self, fname, name, args):
601631
sections = args.get('sections', {})
602632

603633
if not self.check_doc(name, args):
604-
return
634+
return
605635

606636
self.data += f'.TH "{module}" 9 "{module}" "{self.man_date}" "API Manual" LINUX' + "\n"
607637

scripts/lib/kdoc/kdoc_parser.py

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def __init__(self, config, fname):
131131
# Place all potential outputs into an array
132132
self.entries = []
133133

134-
# TODO: rename to emit_message
134+
# TODO: rename to emit_message after removal of kernel-doc.pl
135135
def emit_warning(self, ln, msg, warning=True):
136136
"""Emit a message"""
137137

@@ -157,19 +157,6 @@ def dump_section(self, start_new=True):
157157
name = self.entry.section
158158
contents = self.entry.contents
159159

160-
# TODO: we can prevent dumping empty sections here with:
161-
#
162-
# if self.entry.contents.strip("\n"):
163-
# if start_new:
164-
# self.entry.section = self.section_default
165-
# self.entry.contents = ""
166-
#
167-
# return
168-
#
169-
# But, as we want to be producing the same output of the
170-
# venerable kernel-doc Perl tool, let's just output everything,
171-
# at least for now
172-
173160
if type_param.match(name):
174161
name = type_param.group(1)
175162

@@ -205,7 +192,7 @@ def dump_section(self, start_new=True):
205192
self.entry.section = self.section_default
206193
self.entry.contents = ""
207194

208-
# TODO: rename it to store_declaration
195+
# TODO: rename it to store_declaration after removal of kernel-doc.pl
209196
def output_declaration(self, dtype, name, **args):
210197
"""
211198
Stores the entry into an entry array.
@@ -225,13 +212,13 @@ def output_declaration(self, dtype, name, **args):
225212
args["type"] = dtype
226213
args["warnings"] = self.entry.warnings
227214

228-
# TODO: use colletions.OrderedDict
215+
# TODO: use colletions.OrderedDict to remove sectionlist
229216

230217
sections = args.get('sections', {})
231218
sectionlist = args.get('sectionlist', [])
232219

233220
# Drop empty sections
234-
# TODO: improve it to emit warnings
221+
# TODO: improve empty sections logic to emit warnings
235222
for section in ["Description", "Return"]:
236223
if section in sectionlist:
237224
if not sections[section].rstrip():
@@ -636,7 +623,9 @@ def dump_struct(self, ln, proto):
636623

637624
# Replace macros
638625
#
639-
# TODO: it is better to also move those to the NestedMatch logic,
626+
# TODO: use NestedMatch for FOO($1, $2, ...) matches
627+
#
628+
# it is better to also move those to the NestedMatch logic,
640629
# to ensure that parenthesis will be properly matched.
641630

642631
(Re(r'__ETHTOOL_DECLARE_LINK_MODE_MASK\s*\(([^\)]+)\)', re.S), r'DECLARE_BITMAP(\1, __ETHTOOL_LINK_MODE_MASK_NBITS)'),
@@ -906,7 +895,6 @@ def dump_declaration(self, ln, prototype):
906895
self.dump_struct(ln, prototype)
907896
return
908897

909-
# TODO: handle other types
910898
self.output_declaration(self.entry.decl_type, prototype,
911899
entry=self.entry)
912900

@@ -1680,10 +1668,6 @@ def run(self):
16801668
self.st_inline_name[self.inline_doc_state],
16811669
line)
16821670

1683-
# TODO: not all states allow EXPORT_SYMBOL*, so this
1684-
# can be optimized later on to speedup parsing
1685-
self.process_export(self.config.function_table, line)
1686-
16871671
# Hand this line to the appropriate state handler
16881672
if self.state == self.STATE_NORMAL:
16891673
self.process_normal(ln, line)

scripts/lib/kdoc/kdoc_re.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ class NestedMatch:
131131
will ignore the search string.
132132
"""
133133

134-
# TODO:
134+
# TODO: make NestedMatch handle multiple match groups
135+
#
135136
# Right now, regular expressions to match it are defined only up to
136137
# the start delimiter, e.g.:
137138
#

0 commit comments

Comments
 (0)