diff mbox series

[Unstable/Lunar,3/5] UBUNTU: [Packaging] annotations: Handle tabs in annotations file

Message ID 20230207073607.913994-4-juerg.haefliger@canonical.com
State New
Headers show
Series annotations: Cleanups and splitting | expand

Commit Message

Juerg Haefliger Feb. 7, 2023, 7:36 a.m. UTC
Handle tabs in the annotations file by replacing them with spaces.
While at make the parsing more robust by removing leading and trailing
whitespaces and ignoring empty lines.

Signed-off-by: Juerg Haefliger <juerg.haefliger@canonical.com>
---
 debian/scripts/misc/kconfig/annotations.py | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/debian/scripts/misc/kconfig/annotations.py b/debian/scripts/misc/kconfig/annotations.py
index ee679903d9da..766405c48ec1 100644
--- a/debian/scripts/misc/kconfig/annotations.py
+++ b/debian/scripts/misc/kconfig/annotations.py
@@ -50,13 +50,17 @@  class Annotation(Config):
     Parse body of annotations file
     """
     def _parse_body(self, data: str):
-        # Skip comments
-        data = re.sub(r'(?m)^\s*#.*\n?', '', data)
+        for line in data.splitlines():
+            # Replace tabs with spaces, squeeze multiple into singles and
+            # remove leading and trailing spaces
+            line = line.replace('\t', ' ')
+            line = re.sub(r' +', ' ', line)
+            line = line.strip()
 
-        # Convert multiple spaces to single space to simplifly parsing
-        data = re.sub(r'  *', ' ', data)
+            # Ignore empty lines and comments
+            if not line or line.startswith('#'):
+                continue
 
-        for line in data.splitlines():
             # Handle includes (recursively)
             m = re.match(r'^include\s+"?([^"]*)"?', line)
             if m: