From nobody Thu Dec 18 01:52:38 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 DBE09C2ED; Tue, 28 Jan 2025 00:06:36 +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=1738022797; cv=none; b=QvguzV/cS6XC0ZEeFhAFVvML4/rSepB5U/lMBcS6/DsnNhDPNhS/ZXNSLG9TsRDX8wk6nG7BQAybJKFVtqPNSL5iFL41B3rkoy5XEY49B2qaRJ3aewuKRDr0D/kh68SqGR0G4b3oNcRhyX5A7P5ErVngo92fUbqtpwAlbctTWDM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738022797; c=relaxed/simple; bh=TU7X7H9KcDN4F2n1V6tnT6V+uLjYBbHR0Lyzk9YmCgU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=q/bQ5IWxeNE6g51Y+8g6v2usvsJFgYMMU+cJWv1JfnVtQzgrFqFh5z5Q9MyAgD8CAXuDZ72cUznY3w2ygy/A419HVsgwzzZOxO/2ih7rjSIGi9RI0Tlf7TWCcL/gP7jKX4IVhfWYokdEScZ6xbINjgHqn4EZe4k1E8WeQRwWvgc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XZtLvJFC; 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="XZtLvJFC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D7548C4CEF4; Tue, 28 Jan 2025 00:06:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738022795; bh=TU7X7H9KcDN4F2n1V6tnT6V+uLjYBbHR0Lyzk9YmCgU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XZtLvJFCPElgsXdvhNFgzqPOa23krxpnxtz6hDDyxJKscZB9ZYhiH7TPzPNTSa5RU 4a9PaZSl89lRyYcGkvA1/Bs54Lef0ufD5Owwt7Gjw9/KIcnM4AyvDOQKPiUGXAObMV IRqtC1+W5pDt/ra8ujLllS1i4ACUmAbHZLvTjbAKVPcyEyQ5YDS5tbchRlwEMSs8KT c/ltYM3zJsnEtw9w5eBBfX+Acu4nISb8L1Upc3SVFme8d9ct4vFkZM+R/O5/3O+N7A EW4uaQsFiEIXrua6i2I3e13JUYiCrO7cVofcr31Lhhb6xJddZLu1PWqirsvcY4N+l1 YbCG06HIa4GlA== Received: from mchehab by mail.kernel.org with local (Exim 4.98) (envelope-from ) id 1tcZ7i-0000000DRLT-07kE; Tue, 28 Jan 2025 01:06:34 +0100 From: Mauro Carvalho Chehab To: Linux Doc Mailing List , Jonathan Corbet , Greg Kroah-Hartman Cc: Mauro Carvalho Chehab , "Mauro Carvalho Chehab" , linux-kernel@vger.kernel.org Subject: [RFC v2 17/38] scripts/get_abi.py: use an interactor for ReST output Date: Tue, 28 Jan 2025 01:06:06 +0100 Message-ID: <72a53ca85e554b0c1fb90488d55aa62ec1d7defe.1738020236.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.48.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" Instead of printing all results line per line, use an interactor to return each variable as a separate message. This won't change much when using it via command line, but it will help Sphinx integration by providing an interactor that could be used there to handle ABI symbol by symbol. Signed-off-by: Mauro Carvalho Chehab --- scripts/get_abi.py | 52 ++++++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/scripts/get_abi.py b/scripts/get_abi.py index 73613fb29c1c..2aec1f9dc5aa 100755 --- a/scripts/get_abi.py +++ b/scripts/get_abi.py @@ -349,7 +349,7 @@ class AbiParser: name =3D os.path.join(root, entry.name) =20 if entry.is_dir(): - self.parse_abi(name) + self._parse_abi(name) continue =20 if not entry.is_file(): @@ -378,14 +378,14 @@ class AbiParser: if self.debug & DEBUG_DUMP_ABI_STRUCTS: self.log.debug(pformat(self.data)) =20 - def print_desc_txt(self, desc): + def desc_txt(self, desc): """Print description as found inside ABI files""" =20 desc =3D desc.strip(" \t\n") =20 - print(desc + "\n") + return desc + "\n\n" =20 - def print_desc_rst(self, desc): + def desc_rst(self, desc): """Enrich ReST output by creating cross-references""" =20 # Remove title markups from the description @@ -439,9 +439,9 @@ class AbiParser: =20 new_desc +=3D d + "\n" =20 - print(new_desc + "\n") + return new_desc + "\n\n" =20 - def print_data(self, enable_lineno, output_in_txt, show_file=3DFalse): + def doc(self, enable_lineno, output_in_txt, show_file=3DFalse): """Print ABI at stdout""" =20 part =3D None @@ -456,9 +456,11 @@ class AbiParser: if not show_file and wtype =3D=3D "File": continue =20 + msg =3D "" + if enable_lineno: ln =3D v.get("line_no", 1) - print(f".. LINENO {file_ref[0][0]}#{ln}\n") + msg +=3D f".. LINENO {file_ref[0][0]}#{ln}\n\n" =20 if wtype !=3D "File": cur_part =3D names[0] @@ -470,9 +472,9 @@ class AbiParser: =20 if cur_part and cur_part !=3D part: part =3D cur_part - print(f"{part}\n{"-" * len(part)}\n") + msg +=3D f"{part}\n{"-" * len(part)}\n\n" =20 - print(f".. _{key}:\n") + msg +=3D f".. _{key}:\n\n" =20 max_len =3D 0 for i in range(0, len(names)): # pylint: disable= =3DC0200 @@ -480,45 +482,47 @@ class AbiParser: =20 max_len =3D max(max_len, len(names[i])) =20 - print("+-" + "-" * max_len + "-+") + msg +=3D "+-" + "-" * max_len + "-+\n" for name in names: - print(f"| {name}" + " " * (max_len - len(name)) + " |") - print("+-" + "-" * max_len + "-+") - print() + msg +=3D f"| {name}" + " " * (max_len - len(name)) + "= |\n" + msg +=3D "+-" + "-" * max_len + "-+\n" + msg +=3D "\n" =20 for ref in file_ref: if wtype =3D=3D "File": - print(f".. _{ref[1]}:\n") + msg +=3D f".. _{ref[1]}:\n\n" else: base =3D os.path.basename(ref[0]) - print(f"Defined on file :ref:`{base} <{ref[1]}>`\n") + msg +=3D f"Defined on file :ref:`{base} <{ref[1]}>`\n\= n" =20 if wtype =3D=3D "File": - print(f"{names[0]}\n{"-" * len(names[0])}\n") + msg +=3D f"{names[0]}\n{"-" * len(names[0])}\n\n" =20 desc =3D v.get("description") if not desc and wtype !=3D "File": - print(f"DESCRIPTION MISSING for {names[0]}\n") + msg +=3D f"DESCRIPTION MISSING for {names[0]}\n\n" =20 if desc: if output_in_txt: - self.print_desc_txt(desc) + msg +=3D self.desc_txt(desc) else: - self.print_desc_rst(desc) + msg +=3D self.desc_rst(desc) =20 symbols =3D v.get("symbols") if symbols: - print("Has the following ABI:\n") + msg +=3D "Has the following ABI:\n\n" =20 for w, label in symbols: # Escape special chars from content content =3D self.re_escape.sub(r"\\\1", w) =20 - print(f"- :ref:`{content} <{label}>`\n") + msg +=3D f"- :ref:`{content} <{label}>`\n\n" =20 users =3D v.get("users") if users and users.strip(" \t\n"): - print(f"Users:\n\t{users.strip("\n").replace('\n', '\n\t')= }\n") + msg +=3D f"Users:\n\t{users.strip("\n").replace('\n', '\n\= t')}\n\n" + + yield msg =20 def check_issues(self): """Warn about duplicated ABI entries""" @@ -625,7 +629,9 @@ class AbiRest: parser =3D AbiParser(args.dir, debug=3Dargs.debug) parser.parse_abi() parser.check_issues() - parser.print_data(args.enable_lineno, args.raw, not args.no_file) + + for msg in parser.doc(args.enable_lineno, args.raw, not args.no_fi= le): + print(msg) =20 =20 class AbiValidate: --=20 2.48.1