From fe3f699371855b2db3a9a2bfac0b932904ac0e3d Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Tue, 15 Feb 2022 11:47:30 +0000 Subject: [PATCH 1/5] Add .flake8 file The flake8 validation tool prefers an actual configuration file to inline comments to disable the lint. --- gio/gdbus-2.0/codegen/.flake8 | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 gio/gdbus-2.0/codegen/.flake8 diff --git a/gio/gdbus-2.0/codegen/.flake8 b/gio/gdbus-2.0/codegen/.flake8 new file mode 100644 index 000000000..9450a2832 --- /dev/null +++ b/gio/gdbus-2.0/codegen/.flake8 @@ -0,0 +1,4 @@ +[flake8] +# We are generating long lines through templates +max-line-length = 120 +exclude = __pycache__ From 128ae2b5f55a3067b8772c92d37cd266fbb71fc6 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Tue, 15 Feb 2022 11:48:28 +0000 Subject: [PATCH 2/5] codegen: Fix whitespace This is Python, not C. --- gio/gdbus-2.0/codegen/parser.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gio/gdbus-2.0/codegen/parser.py b/gio/gdbus-2.0/codegen/parser.py index cf8ea5229..142754739 100644 --- a/gio/gdbus-2.0/codegen/parser.py +++ b/gio/gdbus-2.0/codegen/parser.py @@ -77,13 +77,13 @@ class DBusXMLParser: colon_index = line.find(": ") if colon_index == -1: if line.endswith(":"): - symbol = line[0 : len(line) - 1] + symbol = line[0:len(line) - 1] comment_state = DBusXMLParser.COMMENT_STATE_PARAMS else: comment_state = DBusXMLParser.COMMENT_STATE_SKIP else: symbol = line[0:colon_index] - rest_of_line = line[colon_index + 2 :].strip() + rest_of_line = line[colon_index + 2:].strip() if len(rest_of_line) > 0: body += f"{rest_of_line}\n" comment_state = DBusXMLParser.COMMENT_STATE_PARAMS @@ -98,7 +98,7 @@ class DBusXMLParser: body += f"{orig_line}\n" else: param = line[1:colon_index] - docs = line[colon_index + 2 :] + docs = line[colon_index + 2:] params[param] = docs else: comment_state = DBusXMLParser.COMMENT_STATE_BODY From 6ddf760507bb54bdd3b4727ecc3cd787b49427cf Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Tue, 15 Feb 2022 11:48:58 +0000 Subject: [PATCH 3/5] codegen: Remove flake8 lint rule Using `flake8: noqa` disables ALL linting on a file. Adding an error code does not limit the linter to that error. --- gio/gdbus-2.0/codegen/codegen_docbook.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/gio/gdbus-2.0/codegen/codegen_docbook.py b/gio/gdbus-2.0/codegen/codegen_docbook.py index b8d683408..1bfcadd4b 100644 --- a/gio/gdbus-2.0/codegen/codegen_docbook.py +++ b/gio/gdbus-2.0/codegen/codegen_docbook.py @@ -25,10 +25,6 @@ from os import path from . import utils -# Disable line length warnings as wrapping the Docbook templates would be hard -# flake8: noqa: E501 - - # ---------------------------------------------------------------------------------------------------- From 17f38affa210ec0f91d80a6776de9decf4502673 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Tue, 15 Feb 2022 11:51:11 +0000 Subject: [PATCH 4/5] codegen: Add missing closing angular bracket We are matching `` as well as ``, and we end up with broken XML in case the (expanded) description starts with ``. Fixes: #2601 --- gio/gdbus-2.0/codegen/codegen_docbook.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gio/gdbus-2.0/codegen/codegen_docbook.py b/gio/gdbus-2.0/codegen/codegen_docbook.py index 1bfcadd4b..b7280e306 100644 --- a/gio/gdbus-2.0/codegen/codegen_docbook.py +++ b/gio/gdbus-2.0/codegen/codegen_docbook.py @@ -342,7 +342,7 @@ class DocbookCodeGenerator: def expand_paras(self, s, expandParamsAndConstants): s = self.expand(s, expandParamsAndConstants).strip() res = [] - if not s.startswith(""): res.append("") for line in s.split("\n"): line = line.strip() From 47ce6432f32455af1902996b05055c76e839d406 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Tue, 15 Feb 2022 12:14:49 +0000 Subject: [PATCH 5/5] codegen: Verify that we're generating valid XML We should output valid XML even when getting an iffy annotation. --- gio/tests/codegen.py | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/gio/tests/codegen.py b/gio/tests/codegen.py index c95736e39..93508fa62 100644 --- a/gio/tests/codegen.py +++ b/gio/tests/codegen.py @@ -27,10 +27,10 @@ import subprocess import sys import tempfile import unittest +import xml.etree.ElementTree as ET import taptestrunner - # Disable line length warnings as wrapping the C code templates would be hard # flake8: noqa: E501 @@ -625,6 +625,40 @@ G_END_DECLS self.assertEqual(result.out.strip().count("GDBusCallFlags call_flags,"), 2) self.assertEqual(result.out.strip().count("gint timeout_msec,"), 2) + def test_generate_valid_docbook(self): + """Test the basic functionality of the docbook generator.""" + xml_contents = """ + + + + + + + + + + """ + res = self.runCodegenWithInterface( + xml_contents, + "--generate-docbook", + "test", + ) + self.assertEqual("", res.err) + self.assertEqual("", res.out) + with open("test-org.project.Bar.Frobnicator.xml", "r") as f: + self.assertTrue(ET.parse(f) is not None) + if __name__ == "__main__": unittest.main(testRunner=taptestrunner.TAPTestRunner())