From nobody Sat Oct 4 01:41:03 2025 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 D84C02857CF; Thu, 21 Aug 2025 14:21:39 +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=1755786099; cv=none; b=XixoRb/5uheiGz9kbwCW8ycGpcpydByJLDlWDi/2+2X0JXzRA00u8BGvGBEwb29YIzDKK1qaM5JtccZJJN186L97ePSV77haiROzFAS2cwGn750U34SCj2xVTrGX3UtM1ZOiiDBQ+cXh55KF0Y4+YuQzc0d6ryQe1iIr4TG/rjw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755786099; c=relaxed/simple; bh=XLpGjVmiz7KWSgkDl0zwCX9wJOnCvElrKCUuUORJrj4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HhhXKY2f4sNaCkeA2usVInqZD94rYkuq4v7KirfdUuF/vsuZD/BX+1jnDp4lbBkQlImekujx6T5vw7xcWGPp2BbW9DfXYUGXlDUsaslRvw3yneAL6ro4aICZiN+CXjVRl1WJ01nM1fvE9SlHBPFR9/+6FaDFSqN15T+foJRopHk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=S0vyeHCE; 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="S0vyeHCE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 39A51C2BCB5; Thu, 21 Aug 2025 14:21:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1755786099; bh=XLpGjVmiz7KWSgkDl0zwCX9wJOnCvElrKCUuUORJrj4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S0vyeHCE3qfDsq0D4MUgUVrAQDhsIuCEzI/P548tnM9nZ5Muk91VVYMiRaeedD7Wt vTONdyjILJMfX/ePvRar4MwZo7QGt34OAeIoPCd2OiuiJX8XR38CqmKFkqo4p0AJFu xe9TEBOUOyTC4wzlOy7TWgGRz4VWvem0b0vZDy3NQVRv0ouIJqdPhpfxJZMsfeQwG0 phEHbF5YW44ATkBx4awRTIX9X5NjyexQ2E9szQYUqsurXoPTOYpndaqupjL2EfLWmh BKUKPFEkGBom6ji4hWIoDLbspnhuSiYjN7Q3MNksPH8NBWlAzjNhxqXFaoHax/GD+V /60orX2LtmQCA== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1up6Ab-0000000BT92-1ftd; Thu, 21 Aug 2025 16:21:37 +0200 From: Mauro Carvalho Chehab To: Linux Doc Mailing List , Jonathan Corbet Cc: Mauro Carvalho Chehab , Kees Cook , linux-kernel@vger.kernel.org Subject: [PATCH 16/24] docs: kernel_include.py: move code and literal functions Date: Thu, 21 Aug 2025 16:21:22 +0200 Message-ID: <32c0cee9ef85f8d4789f50514d77f719118b3217.1755784930.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.50.1 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" Simplify run() even more by moving the code which handles with code and literal blocks to their own functions. No functional changes. Signed-off-by: Mauro Carvalho Chehab --- Documentation/sphinx/kernel_include.py | 100 +++++++++++++++---------- 1 file changed, 59 insertions(+), 41 deletions(-) diff --git a/Documentation/sphinx/kernel_include.py b/Documentation/sphinx/= kernel_include.py index 4cdd1c77982e..0909eb3a07ea 100755 --- a/Documentation/sphinx/kernel_include.py +++ b/Documentation/sphinx/kernel_include.py @@ -160,6 +160,52 @@ class KernelInclude(Include): =20 return rawtext =20 + def literal(self, path, tab_width, rawtext): + """Output a literal block""" + + # Convert tabs to spaces, if `tab_width` is positive. + if tab_width >=3D 0: + text =3D rawtext.expandtabs(tab_width) + else: + text =3D rawtext + literal_block =3D nodes.literal_block(rawtext, source=3Dpath, + classes=3Dself.options.get("cl= ass", [])) + literal_block.line =3D 1 + self.add_name(literal_block) + if "number-lines" in self.options: + try: + startline =3D int(self.options["number-lines"] or 1) + except ValueError: + raise self.error(":number-lines: with non-integer start va= lue") + endline =3D startline + len(include_lines) + if text.endswith("\n"): + text =3D text[:-1] + tokens =3D NumberLines([([], text)], startline, endline) + for classes, value in tokens: + if classes: + literal_block +=3D nodes.inline(value, value, + classes=3Dclasses) + else: + literal_block +=3D nodes.Text(value, value) + else: + literal_block +=3D nodes.Text(text, text) + return [literal_block] + + def code(self, path, include_lines): + """Output a code block""" + + self.options["source"] =3D path + codeblock =3D CodeBlock(self.name, + [self.options.pop("code")], # arguments + self.options, + include_lines, + self.lineno, + self.content_offset, + self.block_text, + self.state, + self.state_machine) + return codeblock.run() + def run(self): """Include a file as part of the content of this reST file.""" env =3D self.state.document.settings.env @@ -200,6 +246,13 @@ class KernelInclude(Include): startline =3D self.options.get("start-line", None) endline =3D self.options.get("end-line", None) =20 + if "literal" in self.options: + ouptut_type =3D "literal" + elif "code" in self.options: + ouptut_type =3D "code" + else: + ouptut_type =3D "normal" + # Get optional arguments to related to cross-references generation if 'generate-cross-refs' in self.options: rawtext =3D self.read_rawtext_with_xrefs(env, path) @@ -213,50 +266,15 @@ class KernelInclude(Include): =20 rawtext =3D self.apply_range(rawtext) =20 + if ouptut_type =3D=3D "literal": + return self.literal(path, tab_width, rawtext) + include_lines =3D statemachine.string2lines(rawtext, tab_width, convert_whitespace=3DTru= e) - if "literal" in self.options: - # Convert tabs to spaces, if `tab_width` is positive. - if tab_width >=3D 0: - text =3D rawtext.expandtabs(tab_width) - else: - text =3D rawtext - literal_block =3D nodes.literal_block(rawtext, source=3Dpath, - classes=3Dself.options.get= ("class", []) - ) - literal_block.line =3D 1 - self.add_name(literal_block) - if "number-lines" in self.options: - try: - startline =3D int(self.options["number-lines"] or 1) - except ValueError: - raise self.error(":number-lines: with non-integer star= t value") - endline =3D startline + len(include_lines) - if text.endswith("\n"): - text =3D text[:-1] - tokens =3D NumberLines([([], text)], startline, endline) - for classes, value in tokens: - if classes: - literal_block +=3D nodes.inline(value, value, - classes=3Dclasses) - else: - literal_block +=3D nodes.Text(value, value) - else: - literal_block +=3D nodes.Text(text, text) - return [literal_block] =20 - if "code" in self.options: - self.options["source"] =3D path - codeblock =3D CodeBlock(self.name, - [self.options.pop("code")], # arguments - self.options, - include_lines, # content - self.lineno, - self.content_offset, - self.block_text, - self.state, - self.state_machine) - return codeblock.run() + if ouptut_type =3D=3D "code": + return self.code(path, include_lines) + self.state_machine.insert_input(include_lines, path) return [] =20 --=20 2.50.1