Skip to content

Commit

Permalink
Improve auto-docstring generation
Browse files Browse the repository at this point in the history
  • Loading branch information
mementum committed Mar 11, 2020
1 parent 9b6004b commit f1c8ef9
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions btalib/meta/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


def wrap_indent(txt, ilevel=0, ichar=' ', width=78, cr=1):
ifill = (ilevel + 1) * ichar
ifill = ilevel * ichar
wrapped_lines = []
for line in txt.splitlines():
wrapped = textwrap.wrap(
Expand All @@ -29,11 +29,18 @@ def wrap_indent(txt, ilevel=0, ichar=' ', width=78, cr=1):
return '\n'*cr + '\n'.join(wrapped_lines)


def process_docstring(d):
slines = d.split('\n')
slines2 = textwrap.dedent('\n'.join(slines[1:])).split('\n')
return '\n'.join([slines[0]] + slines2)


def _generate(cls, bases, dct, **kwargs):
# Get actual docstring

cls.__doc_orig__ = clsdoc = (cls.__doc__ or '').lstrip('\n').rstrip()
gendoc = clsdoc
cls.__doc_orig__ = clsdoc = (cls.__doc__ or '')

gendoc = process_docstring(clsdoc)

if getattr(cls, 'alias', None):
txt = '\n'
Expand Down Expand Up @@ -81,6 +88,6 @@ def _generate(cls, bases, dct, **kwargs):
if tadoc:
txt = 'TA-LIB (with compatibility flag "_talib=True"):'
gendoc += wrap_indent(txt, cr=2)
gendoc += wrap_indent(' - ' + tadoc)
gendoc += '\n\n' + process_docstring(tadoc)

cls.__doc__ = gendoc

0 comments on commit f1c8ef9

Please sign in to comment.