Skip to content

Commit 66c3bf9

Browse files
mchehabJonathan Corbet
authored andcommitted
docs: python: abi_parser: do some improvements at documentation
Add documentation for two consts and ensure that all sentenses will end with a dot. Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org> Signed-off-by: Jonathan Corbet <corbet@lwn.net> Message-ID: <c5756d7fd70697890130b41b2856c59144d01844.1768838938.git.mchehab+huawei@kernel.org>
1 parent 9fa4ee7 commit 66c3bf9

1 file changed

Lines changed: 18 additions & 15 deletions

File tree

tools/lib/python/abi/abi_parser.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,17 @@
2121

2222

2323
class AbiParser:
24-
"""Main class to parse ABI files"""
24+
"""Main class to parse ABI files."""
2525

26+
#: Valid tags at Documentation/ABI.
2627
TAGS = r"(what|where|date|kernelversion|contact|description|users)"
28+
29+
#: ABI elements that will auto-generate cross-references.
2730
XREF = r"(?:^|\s|\()(\/(?:sys|config|proc|dev|kvd)\/[^,.:;\)\s]+)(?:[,.:;\)\s]|\Z)"
2831

2932
def __init__(self, directory, logger=None,
3033
enable_lineno=False, show_warnings=True, debug=0):
31-
"""Stores arguments for the class and initialize class vars"""
34+
"""Stores arguments for the class and initialize class vars."""
3235

3336
self.directory = directory
3437
self.enable_lineno = enable_lineno
@@ -65,7 +68,7 @@ def __init__(self, directory, logger=None,
6568
self.re_xref_node = re.compile(self.XREF)
6669

6770
def warn(self, fdata, msg, extra=None):
68-
"""Displays a parse error if warning is enabled"""
71+
"""Displays a parse error if warning is enabled."""
6972

7073
if not self.show_warnings:
7174
return
@@ -77,7 +80,7 @@ def warn(self, fdata, msg, extra=None):
7780
self.log.warning(msg)
7881

7982
def add_symbol(self, what, fname, ln=None, xref=None):
80-
"""Create a reference table describing where each 'what' is located"""
83+
"""Create a reference table describing where each 'what' is located."""
8184

8285
if what not in self.what_symbols:
8386
self.what_symbols[what] = {"file": {}}
@@ -92,7 +95,7 @@ def add_symbol(self, what, fname, ln=None, xref=None):
9295
self.what_symbols[what]["xref"] = xref
9396

9497
def _parse_line(self, fdata, line):
95-
"""Parse a single line of an ABI file"""
98+
"""Parse a single line of an ABI file."""
9699

97100
new_what = False
98101
new_tag = False
@@ -264,7 +267,7 @@ def _parse_line(self, fdata, line):
264267
self.warn(fdata, "Unexpected content", line)
265268

266269
def parse_readme(self, nametag, fname):
267-
"""Parse ABI README file"""
270+
"""Parse ABI README file."""
268271

269272
nametag["what"] = ["Introduction"]
270273
nametag["path"] = "README"
@@ -282,7 +285,7 @@ def parse_readme(self, nametag, fname):
282285
nametag["description"] += line
283286

284287
def parse_file(self, fname, path, basename):
285-
"""Parse a single file"""
288+
"""Parse a single file."""
286289

287290
ref = f"abi_file_{path}_{basename}"
288291
ref = self.re_unprintable.sub("_", ref).strip("_")
@@ -348,7 +351,7 @@ def parse_file(self, fname, path, basename):
348351
self.add_symbol(what=w, fname=fname, xref=fdata.key)
349352

350353
def _parse_abi(self, root=None):
351-
"""Internal function to parse documentation ABI recursively"""
354+
"""Internal function to parse documentation ABI recursively."""
352355

353356
if not root:
354357
root = self.directory
@@ -377,23 +380,23 @@ def _parse_abi(self, root=None):
377380
self.parse_file(name, path, basename)
378381

379382
def parse_abi(self, root=None):
380-
"""Parse documentation ABI"""
383+
"""Parse documentation ABI."""
381384

382385
self._parse_abi(root)
383386

384387
if self.debug & AbiDebug.DUMP_ABI_STRUCTS:
385388
self.log.debug(pformat(self.data))
386389

387390
def desc_txt(self, desc):
388-
"""Print description as found inside ABI files"""
391+
"""Print description as found inside ABI files."""
389392

390393
desc = desc.strip(" \t\n")
391394

392395
return desc + "\n\n"
393396

394397
def xref(self, fname):
395398
"""
396-
Converts a Documentation/ABI + basename into a ReST cross-reference
399+
Converts a Documentation/ABI + basename into a ReST cross-reference.
397400
"""
398401

399402
xref = self.file_refs.get(fname)
@@ -403,7 +406,7 @@ def xref(self, fname):
403406
return xref
404407

405408
def desc_rst(self, desc):
406-
"""Enrich ReST output by creating cross-references"""
409+
"""Enrich ReST output by creating cross-references."""
407410

408411
# Remove title markups from the description
409412
# Having titles inside ABI files will only work if extra
@@ -459,7 +462,7 @@ def desc_rst(self, desc):
459462

460463
def doc(self, output_in_txt=False, show_symbols=True, show_file=True,
461464
filter_path=None):
462-
"""Print ABI at stdout"""
465+
"""Print ABI at stdout."""
463466

464467
part = None
465468
for key, v in sorted(self.data.items(),
@@ -549,7 +552,7 @@ def doc(self, output_in_txt=False, show_symbols=True, show_file=True,
549552
yield (msg, file_ref[0][0], ln)
550553

551554
def check_issues(self):
552-
"""Warn about duplicated ABI entries"""
555+
"""Warn about duplicated ABI entries."""
553556

554557
for what, v in self.what_symbols.items():
555558
files = v.get("file")
@@ -575,7 +578,7 @@ def check_issues(self):
575578
self.log.warning("%s is defined %d times: %s", what, len(f), "; ".join(f))
576579

577580
def search_symbols(self, expr):
578-
""" Searches for ABI symbols """
581+
""" Searches for ABI symbols."""
579582

580583
regex = re.compile(expr, re.I)
581584

0 commit comments

Comments
 (0)