From 07de1d515e35dc8541aa11960a718003a59a8a05 Mon Sep 17 00:00:00 2001 From: lojack5 <1458329+lojack5@users.noreply.github.com> Date: Tue, 17 Oct 2023 14:49:19 -0600 Subject: [PATCH] [etgtools] Disable text wrapping for specific lines in docstrings The line-wrapping causes issues once the python signatures become too long, as textwrap isn't smart enough to split the lines on valid continuation points for code. I had one instance of splitting a line in the middle of a string -> SyntaxError on next run of etg due to the generated PYI file having an unterminated string. Specificially, disable splitting for lines that start (ignoring spaces) with a specific string - in this case any line starting with the name of the function or method this is a docstring for. --- etgtools/generators.py | 7 +++++-- etgtools/sip_generator.py | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/etgtools/generators.py b/etgtools/generators.py index 7b164c88..ba94a662 100644 --- a/etgtools/generators.py +++ b/etgtools/generators.py @@ -81,12 +81,15 @@ def nci(text, numSpaces=0, stripLeading=True): return newText -def wrapText(text): +def wrapText(text, dontWrap: str = ''): import textwrap lines = [] tw = textwrap.TextWrapper(width=70, break_long_words=False) for line in text.split('\n'): - lines.append(tw.fill(line)) + if dontWrap and line.lstrip().startswith(dontWrap): + lines.append(line) + else: + lines.append(tw.fill(line)) return '\n'.join(lines) diff --git a/etgtools/sip_generator.py b/etgtools/sip_generator.py index 38db80b1..56b8e9bf 100644 --- a/etgtools/sip_generator.py +++ b/etgtools/sip_generator.py @@ -610,7 +610,7 @@ from .%s import * # get the docstring text text = nci(extractors.flattenNode(item.briefDoc, False)) - text = wrapText(text) + text = wrapText(text, item.pyName or item.name) #if isinstance(item, extractors.ClassDef):