From: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Jonathan Corbet <corbet@lwn.net>,
Akira Yokosawa <akiyks@gmail.com>,
Nicolas Schier <nicolas.schier@linux.dev>,
Randy Dunlap <rdunlap@infradead.org>,
Stephen Rothwell <sfr@canb.auug.org.au>,
Kees Cook <kees@kernel.org>,
linux-doc@vger.kernel.org, linux-kbuild@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/4] docs: kerneldoc.py: add try/except blocks for kernel-doc class errors
Date: Tue, 20 May 2025 17:40:35 +0200 [thread overview]
Message-ID: <20250520174035.5f193ec3@sal.lan> (raw)
In-Reply-To: <20250520165024.7447a107@sal.lan>
Em Tue, 20 May 2025 16:50:24 +0200
Mauro Carvalho Chehab <mchehab+huawei@kernel.org> escreveu:
> Em Tue, 20 May 2025 17:22:27 +0300
> Andy Shevchenko <andriy.shevchenko@linux.intel.com> escreveu:
>
> > On Tue, May 20, 2025 at 03:33:08PM +0200, Mauro Carvalho Chehab wrote:
> > > Replicate the same behavior as what's done with kernel-doc.pl:
> > > continue building docs even when there are exceptions.
> >
> > ...
> >
> > > + logger.warning("kernel-doc '%s' processing failed with: %s" %
> > > + (cmd_str(cmd), str(e)))
> >
> > > + logger.warning("kernel-doc '%s' processing failed with: %s" %
> > > + (cmd_str(cmd), str(e)))
> >
> > The prefix of the message is the same for different (semantically) places.
> > Is it okay? (I would expect them to slightly differ, but I dunno if
> > cmd here is the same, perhaps that's enough for distinguishing the two.)
>
> I guess it should be OK, as the "%s" variables are the ones that will
> actually help to provide a hint about the issue. See, in practice, if
> one wants to check what crashed, the procedure would likely be to run
> the command line, given by "cmd_str(cmd)" and see what output was produced.
On a second thought, the try/except logic there is too complex. We
need just one to cover all cases. Also, "str(e)" is not the best,
as it doesn't really show the error. "pformat(e)" works a lot better:
$ make htmldocs
Using alabaster theme
Using Python kernel-doc
Cannot find file ./drivers/gpio/gpiolib-acpi.c
Cannot find file ./drivers/gpio/gpiolib-acpi.c
WARNING: kernel-doc './scripts/kernel-doc.py -rst -enable-lineno -export ./drivers/gpio/gpiolib-acpi.c' processing failed with: KeyError('./drivers/gpio/gpiolib-acpi.c')
Documentation/arch/powerpc/htm.rst: WARNING: document isn't included in any toctree
See enclosed patch (to be applied after this series).
Regards,
Mauro
---
[PATCH] docs: kerneldoc.py: simplify exception handling logic
Instead of having try/except everywhere, place them on a common
place.
While here, get rid of some bogus logs.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
diff --git a/Documentation/sphinx/kerneldoc.py b/Documentation/sphinx/kerneldoc.py
index 833cb0285afc..3f9754b84566 100644
--- a/Documentation/sphinx/kerneldoc.py
+++ b/Documentation/sphinx/kerneldoc.py
@@ -40,6 +40,7 @@ from docutils.parsers.rst import directives, Directive
import sphinx
from sphinx.util.docutils import switch_source_input
from sphinx.util import logging
+from pprint import pformat
srctree = os.path.abspath(os.environ["srctree"])
sys.path.insert(0, os.path.join(srctree, "scripts/lib/kdoc"))
@@ -49,7 +50,7 @@ from kdoc_output import RestFormat
__version__ = '1.0'
kfiles = None
-logger = logging.getLogger('kerneldoc')
+logger = logging.getLogger(__name__)
def cmd_str(cmd):
"""
@@ -190,46 +191,35 @@ class KernelDocDirective(Directive):
return cmd
- def run_cmd(self):
+ def run_cmd(self, cmd):
"""
Execute an external kernel-doc command.
"""
env = self.state.document.settings.env
- cmd = self.handle_args()
if self.verbose >= 1:
- print(cmd_str(cmd))
+ logger.info(cmd_str(cmd))
node = nodes.section()
- try:
- logger.verbose("calling kernel-doc '%s'" % (" ".join(cmd)))
-
- p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- out, err = p.communicate()
-
- out, err = codecs.decode(out, 'utf-8'), codecs.decode(err, 'utf-8')
+ p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ out, err = p.communicate()
- if p.returncode != 0:
- sys.stderr.write(err)
+ out, err = codecs.decode(out, 'utf-8'), codecs.decode(err, 'utf-8')
- logger.warning("kernel-doc '%s' failed with return code %d"
- % (" ".join(cmd), p.returncode))
- return [nodes.error(None, nodes.paragraph(text = "kernel-doc missing"))]
- elif env.config.kerneldoc_verbosity > 0:
- sys.stderr.write(err)
+ if p.returncode != 0:
+ sys.stderr.write(err)
- except Exception as e: # pylint: disable=W0703
- logger.warning("kernel-doc '%s' processing failed with: %s" %
- (" ".join(cmd), str(e)))
+ logger.warning("kernel-doc '%s' failed with return code %d"
+ % (" ".join(cmd), p.returncode))
return [nodes.error(None, nodes.paragraph(text = "kernel-doc missing"))]
+ elif env.config.kerneldoc_verbosity > 0:
+ sys.stderr.write(err)
filenames = self.parse_args["file_list"]
for filename in filenames:
- ret = self.parse_msg(filename, node, out, cmd)
- if ret:
- return ret
+ self.parse_msg(filename, node, out, cmd)
return node.children
@@ -240,71 +230,62 @@ class KernelDocDirective(Directive):
env = self.state.document.settings.env
- try:
- lines = statemachine.string2lines(out, self.tab_width,
- convert_whitespace=True)
- result = ViewList()
-
- lineoffset = 0;
- line_regex = re.compile(r"^\.\. LINENO ([0-9]+)$")
- for line in lines:
- match = line_regex.search(line)
- if match:
- # sphinx counts lines from 0
- lineoffset = int(match.group(1)) - 1
- # we must eat our comments since the upset the markup
- else:
- doc = str(env.srcdir) + "/" + env.docname + ":" + str(self.lineno)
- result.append(line, doc + ": " + filename, lineoffset)
- lineoffset += 1
-
- self.do_parse(result, node)
-
- except Exception as e: # pylint: disable=W0703
- logger.warning("kernel-doc '%s' processing failed with: %s" %
- (cmd_str(cmd), str(e)))
- return [nodes.error(None, nodes.paragraph(text = "kernel-doc missing"))]
+ lines = statemachine.string2lines(out, self.tab_width,
+ convert_whitespace=True)
+ result = ViewList()
+
+ lineoffset = 0;
+ line_regex = re.compile(r"^\.\. LINENO ([0-9]+)$")
+ for line in lines:
+ match = line_regex.search(line)
+ if match:
+ # sphinx counts lines from 0
+ lineoffset = int(match.group(1)) - 1
+ # we must eat our comments since the upset the markup
+ else:
+ doc = str(env.srcdir) + "/" + env.docname + ":" + str(self.lineno)
+ result.append(line, doc + ": " + filename, lineoffset)
+ lineoffset += 1
- return None
+ self.do_parse(result, node)
- def run_kdoc(self, kfiles):
+ def run_kdoc(self, cmd, kfiles):
"""
Execute kernel-doc classes directly instead of running as a separate
command.
"""
- cmd = self.handle_args()
env = self.state.document.settings.env
node = nodes.section()
- try:
- kfiles.parse(**self.parse_args)
- filenames = self.parse_args["file_list"]
-
- msgs = kfiles.msg(**self.msg_args, filenames=filenames)
- for filename, out in msgs:
- if self.verbose >= 1:
- print(cmd_str(cmd))
+ kfiles.parse(**self.parse_args)
+ filenames = self.parse_args["file_list"]
- ret = self.parse_msg(filename, node, out, cmd)
- if ret:
- return ret
+ msgs = kfiles.msg(**self.msg_args, filenames=filenames)
+ for filename, out in msgs:
+ if self.verbose >= 1:
+ print(cmd_str(cmd))
- except Exception as e: # pylint: disable=W0703
- logger.warning("kernel-doc '%s' processing failed with: %s" %
- (cmd_str(cmd), str(e)))
- return [nodes.error(None, nodes.paragraph(text = "kernel-doc missing"))]
+ self.parse_msg(filename, node, out, cmd)
return node.children
def run(self):
global kfiles
- if kfiles:
- return self.run_kdoc(kfiles)
- else:
- return self.run_cmd()
+ cmd = self.handle_args()
+
+ try:
+ if kfiles:
+ return self.run_kdoc(cmd, kfiles)
+ else:
+ return self.run_cmd(cmd)
+
+ except Exception as e: # pylint: disable=W0703
+ logger.warning("kernel-doc '%s' processing failed with: %s" %
+ (cmd_str(cmd), pformat(e)))
+ return [nodes.error(None, nodes.paragraph(text = "kernel-doc missing"))]
def do_parse(self, result, node):
with switch_source_input(self.state, result):
next prev parent reply other threads:[~2025-05-20 15:40 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-20 13:33 [PATCH 0/4] Some kernel-doc fixes Mauro Carvalho Chehab
2025-05-20 13:33 ` [PATCH 1/4] docs: kerneldoc.py: don't use Sphinx logger Mauro Carvalho Chehab
2025-05-20 13:33 ` [PATCH 2/4] scripts: kernel-doc: prevent a KeyError when checking output Mauro Carvalho Chehab
2025-05-20 13:33 ` [PATCH 3/4] docs: kerneldoc.py: add try/except blocks for kernel-doc class errors Mauro Carvalho Chehab
2025-05-20 14:22 ` Andy Shevchenko
2025-05-20 14:50 ` Mauro Carvalho Chehab
2025-05-20 15:40 ` Mauro Carvalho Chehab [this message]
2025-05-20 13:33 ` [PATCH 4/4] MAINTAINERS: update linux-doc entry to cover new Python scripts Mauro Carvalho Chehab
2025-05-20 14:17 ` [PATCH 0/4] Some kernel-doc fixes Andy Shevchenko
2025-05-20 14:31 ` Mauro Carvalho Chehab
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250520174035.5f193ec3@sal.lan \
--to=mchehab+huawei@kernel.org \
--cc=akiyks@gmail.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=corbet@lwn.net \
--cc=kees@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nicolas.schier@linux.dev \
--cc=rdunlap@infradead.org \
--cc=sfr@canb.auug.org.au \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).