mirror of
https://github.com/wxWidgets/Phoenix.git
synced 2025-12-15 17:20:07 +01:00
[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:
@@ -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)
|
||||
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user