From nobody Sat Oct 4 01:42:11 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 AD795283FFF; 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=Y1Q9u0G2AD0eYzUsSLLlYxsazmTXoY5k8Bam40EQtvQDFlU4ZB5OHxeOjQE6VbU459zqpIkH4BGoE7kbpfQgS7uOEzLzVlEJDbXtiAtaEWQuh7mpyCm3GsvOwAypd92McE3QlCJuQX7qa4CTk6yKPgmStopT8LwB6ajsti6E96Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755786099; c=relaxed/simple; bh=qu5eqKXlag7ALsP16SkP+d9fl76226iDf9IK5Sgc2pE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=e2aEEb9WZWc+jk4DktyLu5jirh5n9r8aWiwRDO/6PG9f15yb5idiTUU2BWcP+b0/6O4wPhWOZuRgaQKWZqLbaaEKH/GqG0aglnhDu674CbdmSjraXKA0eDlfQs1wuAwOQejI64b8klTYeWouOi93JL8ZvypvZP2SnX1wfOwguvA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iRinbi0d; 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="iRinbi0d" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2A2FDC19425; 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=qu5eqKXlag7ALsP16SkP+d9fl76226iDf9IK5Sgc2pE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iRinbi0d6r5qMfaikiw5DtkpvrdOOyetl0qHefidh+cg+lNQdpwcx+xA6+sfu1QeN KQ0JmDXxCTRcMhXD2jUgJ0K+zO7K891bjKeGpVHmpkdjQfbusB7/W6ovjI10+ASGgD RQejKDkArVxdx8ZIwnwTiBRNDdQ26eOPiiEe4uzalKCianmRw3TJ1sR39EpuzaVb7t n3DVWanaRyhQDddqN2AoEC8TrSJgSGyApATG2krXPQQFAPSnoK7pHlW04sQK5nk3ey 4t0IN/TFjo0lGd8fGifxuBJqSPwYxEOJHruLwK3aKCzxetWHqDWnEJzZtXcAbjquNP 1anIs8lJN6AXQ== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1up6Ab-0000000BT8u-1SLl; 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 14/24] docs: kernel_include.py: move range logic to a separate function Date: Thu, 21 Aug 2025 16:21:20 +0200 Message-ID: <811121f0b40c788936c6aec92a27500767b9b0dd.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" Cleanup run() function by moving the range logic to a separate function. Here, I ended checking the current Sphinx implementation, as it has some extra logic for the range check. Signed-off-by: Mauro Carvalho Chehab --- Documentation/sphinx/kernel_include.py | 51 +++++++++++++++++--------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/Documentation/sphinx/kernel_include.py b/Documentation/sphinx/= kernel_include.py index ef86ee9e79d6..c5f4f34e22cb 100755 --- a/Documentation/sphinx/kernel_include.py +++ b/Documentation/sphinx/kernel_include.py @@ -131,6 +131,38 @@ class KernelInclude(Include): =20 return parser.gen_output() =20 + def apply_range(self, rawtext): + # Get to-be-included content + startline =3D self.options.get('start-line', None) + endline =3D self.options.get('end-line', None) + try: + if startline or (endline is not None): + lines =3D rawtext.splitlines() + rawtext =3D '\n'.join(lines[startline:endline]) + except UnicodeError as error: + raise self.severe(f'Problem with "{self.name}" directive:\n' + + io.error_string(error)) + # start-after/end-before: no restrictions on newlines in match-tex= t, + # and no restrictions on matching inside lines vs. line boundaries + after_text =3D self.options.get("start-after", None) + if after_text: + # skip content in rawtext before *and incl.* a matching text + after_index =3D rawtext.find(after_text) + if after_index < 0: + raise self.severe('Problem with "start-after" option of "%= s" ' + "directive:\nText not found." % self.nam= e) + rawtext =3D rawtext[after_index + len(after_text) :] + before_text =3D self.options.get("end-before", None) + if before_text: + # skip content in rawtext after *and incl.* a matching text + before_index =3D rawtext.find(before_text) + if before_index < 0: + raise self.severe('Problem with "end-before" option of "%s= " ' + "directive:\nText not found." % self.nam= e) + rawtext =3D rawtext[:before_index] + + return rawtext + def run(self): """Include a file as part of the content of this reST file.""" env =3D self.state.document.settings.env @@ -185,24 +217,7 @@ class KernelInclude(Include): else: rawtext =3D self.read_rawtext(path, encoding) =20 - # start-after/end-before: no restrictions on newlines in match-tex= t, - # and no restrictions on matching inside lines vs. line boundaries - after_text =3D self.options.get("start-after", None) - if after_text: - # skip content in rawtext before *and incl.* a matching text - after_index =3D rawtext.find(after_text) - if after_index < 0: - raise self.severe('Problem with "start-after" option of "%= s" ' - "directive:\nText not found." % self.nam= e) - rawtext =3D rawtext[after_index + len(after_text) :] - before_text =3D self.options.get("end-before", None) - if before_text: - # skip content in rawtext after *and incl.* a matching text - before_index =3D rawtext.find(before_text) - if before_index < 0: - raise self.severe('Problem with "end-before" option of "%s= " ' - "directive:\nText not found." % self.nam= e) - rawtext =3D rawtext[:before_index] + rawtext =3D self.apply_range(rawtext) =20 include_lines =3D statemachine.string2lines(rawtext, tab_width, convert_whitespace=3DTru= e) --=20 2.50.1