From nobody Mon Feb 9 00:56:15 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D905B22F169; Fri, 25 Apr 2025 07:13:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745565238; cv=none; b=jH7X5i0Hm8NnCNdxgo4LbygwfUPbtBaBG7u483jqsZU0i19XGClm0JLMsnsfU5yClXumdHllpaXYzmBUzzg+hqXjwhBnQ+wUnEm30LOfChhpVf4rFQ6pgNkzcsVWS/cIBgsQhpTBABbf2A1JrkEUcMMr8LGatkxH5fAgtQvQGwc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745565238; c=relaxed/simple; bh=8ht6CFnJ+xOrz1MUeE1fJUbi02R0O8GllLmGzGZXdI8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V4vAylJ3J123jErK9qj4h/rRX+1/J4rh/fLsEkKVrPXEZC1eGjkVed/t5XVbIYURpiR9ezRuaUvhU8Dfb+/ntDoFuVokaD+TQyhtDaS7W1kfmpdVX976fHTmCtPw+MGsCVDENRQ8DscLVx+19mhS4ZLITrssbq5WaKtjMtDdIrY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=W4xqKXxg; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="W4xqKXxg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6F75DC4CEEB; Fri, 25 Apr 2025 07:13:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1745565238; bh=8ht6CFnJ+xOrz1MUeE1fJUbi02R0O8GllLmGzGZXdI8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W4xqKXxgE2kAuh2nQCFC89WDz7OrprgGEjOwuKb1cmBpBV+Jh1XurURM1yEcN4Gst kzrwSA+3t2gB7xZ0RmRP9542aEHFy0nBX+th+LOjKjCEYUtaC5WK4YL2ZXi2ywetRv Dvx5UBm3B4XnYPvokDKqyQVXW1ZQdBvLV+P7yGsum8HsbYrjYBwl0DvhUnMAuZnmm/ weIUUioXUeCnQnB+SpkLZYk+Koku4ONi99guaA84qPU76IZwZGRIZe41QT84Xk5xoI xiUQTsVXZ47DK7nOt7ONpTzErVLoqhKJ0ujUmF3XbkcUQ4Af+RwP7ZZ5E0U4vnENoG QqC4qHdf1O54Q== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1u8DFv-00000000TG0-43yQ; Fri, 25 Apr 2025 15:13:51 +0800 From: Mauro Carvalho Chehab To: Linux Doc Mailing List , Jonathan Corbet Cc: Mauro Carvalho Chehab , Kees Cook , linux-kernel@vger.kernel.org Subject: [PATCH 1/3] docs: Sphinx: kerneldoc: only initialize kernel-doc classes once Date: Fri, 25 Apr 2025 15:13:38 +0800 Message-ID: X-Mailer: git-send-email 2.49.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: Mauro Carvalho Chehab Content-Type: text/plain; charset="utf-8" Instead of re-creating the objects every time, initialize it just once. This allows caching previously parsed objects. Signed-off-by: Mauro Carvalho Chehab --- Documentation/sphinx/kerneldoc.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/Documentation/sphinx/kerneldoc.py b/Documentation/sphinx/kerne= ldoc.py index 27baf28fb754..b713a2c4a615 100644 --- a/Documentation/sphinx/kerneldoc.py +++ b/Documentation/sphinx/kerneldoc.py @@ -48,7 +48,8 @@ from kdoc_files import KernelFiles from kdoc_output import RestFormat =20 __version__ =3D '1.0' -use_kfiles =3D False +kfiles =3D None +logger =3D logging.getLogger('kerneldoc') =20 def cmd_str(cmd): """ @@ -86,7 +87,6 @@ class KernelDocDirective(Directive): 'functions': directives.unchanged, } has_content =3D False - logger =3D logging.getLogger('kerneldoc') verbose =3D 0 =20 parse_args =3D {} @@ -204,7 +204,7 @@ class KernelDocDirective(Directive): node =3D nodes.section() =20 try: - self.logger.verbose("calling kernel-doc '%s'" % (" ".join(cmd)= )) + logger.verbose("calling kernel-doc '%s'" % (" ".join(cmd))) =20 p =3D subprocess.Popen(cmd, stdout=3Dsubprocess.PIPE, stderr= =3Dsubprocess.PIPE) out, err =3D p.communicate() @@ -214,14 +214,14 @@ class KernelDocDirective(Directive): if p.returncode !=3D 0: sys.stderr.write(err) =20 - self.logger.warning("kernel-doc '%s' failed with return co= de %d" + logger.warning("kernel-doc '%s' failed with return code %d" % (" ".join(cmd), p.returncode)) return [nodes.error(None, nodes.paragraph(text =3D "kernel= -doc missing"))] elif env.config.kerneldoc_verbosity > 0: sys.stderr.write(err) =20 except Exception as e: # pylint: disable=3DW0703 - self.logger.warning("kernel-doc '%s' processing failed with: %= s" % + logger.warning("kernel-doc '%s' processing failed with: %s" % (" ".join(cmd), str(e))) return [nodes.error(None, nodes.paragraph(text =3D "kernel-doc= missing"))] =20 @@ -261,7 +261,7 @@ class KernelDocDirective(Directive): self.do_parse(result, node) =20 except Exception as e: # pylint: disable=3DW0703 - self.logger.warning("kernel-doc '%s' processing failed with: %= s" % + logger.warning("kernel-doc '%s' processing failed with: %s" % (cmd_str(cmd), str(e))) return [nodes.error(None, nodes.paragraph(text =3D "kernel-doc= missing"))] =20 @@ -292,11 +292,9 @@ class KernelDocDirective(Directive): return node.children =20 def run(self): - global use_kfiles + global kfiles =20 - if use_kfiles: - out_style =3D RestFormat() - kfiles =3D KernelFiles(out_style=3Dout_style, logger=3Dself.lo= gger) + if kfiles: return self.run_kdoc(kfiles) else: return self.run_cmd() @@ -306,13 +304,14 @@ class KernelDocDirective(Directive): self.state.nested_parse(result, 0, node, match_titles=3D1) =20 def setup_kfiles(app): - global use_kfiles + global kfiles =20 kerneldoc_bin =3D app.env.config.kerneldoc_bin =20 if kerneldoc_bin and kerneldoc_bin.endswith("kernel-doc.py"): print("Using Python kernel-doc") - use_kfiles =3D True + out_style =3D RestFormat() + kfiles =3D KernelFiles(out_style=3Dout_style, logger=3Dlogger) else: print(f"Using {kerneldoc_bin}") =20 --=20 2.49.0