From 154e00f9a370b2b40f3b62ca9b6b29f407986c00 Mon Sep 17 00:00:00 2001 From: Joao Matos Date: Mon, 3 Mar 2025 22:34:45 +0000 Subject: [PATCH] Tools: Improve identation handling for attribute docstring comments. --- .../bindings/model/generateModel_Python.py | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/Tools/bindings/model/generateModel_Python.py b/src/Tools/bindings/model/generateModel_Python.py index 38d3ae7db7..70776a3307 100644 --- a/src/Tools/bindings/model/generateModel_Python.py +++ b/src/Tools/bindings/model/generateModel_Python.py @@ -46,28 +46,30 @@ def _parse_docstring_for_documentation(docstring: str) -> Documentation: if not docstring: return Documentation() - lines = docstring.strip().split("\n") + import textwrap + + # Remove common indentation + dedented_docstring = textwrap.dedent(docstring).strip() + lines = dedented_docstring.split("\n") user_docu_lines = [] for raw_line in lines: - line = raw_line.strip() - if line.startswith("DeveloperDocu:"): - dev_docu = line.split("DeveloperDocu:", 1)[1].strip() - elif line.startswith("UserDocu:"): - user_docu = line.split("UserDocu:", 1)[1].strip() - elif line.startswith("Author:"): + stripped_line = raw_line.strip() + if stripped_line.startswith("DeveloperDocu:"): + dev_docu = stripped_line.split("DeveloperDocu:", 1)[1].strip() + elif stripped_line.startswith("UserDocu:"): + user_docu = stripped_line.split("UserDocu:", 1)[1].strip() + elif stripped_line.startswith("Author:"): # e.g. "Author: John Doe (john@example.com)" - # naive approach: - author_part = line.split("Author:", 1)[1].strip() - # attempt to find email in parentheses + author_part = stripped_line.split("Author:", 1)[1].strip() match = re.search(r"(.*?)\s*\((.*?)\)", author_part) if match: author_name = match.group(1).strip() author_email = match.group(2).strip() else: author_name = author_part - elif line.startswith("Licence:"): - author_licence = line.split("Licence:", 1)[1].strip() + elif stripped_line.startswith("Licence:"): + author_licence = stripped_line.split("Licence:", 1)[1].strip() else: user_docu_lines.append(raw_line)