[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.
This commit is contained in:
lojack5
2023-10-17 14:49:19 -06:00
parent a118428670
commit 07de1d515e
2 changed files with 6 additions and 3 deletions

View File

@@ -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)

View File

@@ -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):