Commit 8e6bae8b authored by Robert McGibbon's avatar Robert McGibbon
Browse files

Fix some issues with generating doxygen python API docs

parent c8443904
from __future__ import print_function from __future__ import print_function
from numpydoc.docscrape import NumpyDocString import re
import sys import sys
import textwrap import textwrap
from inspect import cleandoc from inspect import cleandoc
from numpydoc.docscrape import NumpyDocString
# Doxygen does a bad job of generating documentation based on docstrings. This script is run as a filter # Doxygen does a bad job of generating documentation based on docstrings.
# on each file, and converts the docstrings into Doxygen style comments so we get better documentation. # This script is run as a filter
# on each file, and converts the docstrings into Doxygen style comments
# so we get better documentation.
input = open(sys.argv[1]) input = open(sys.argv[1])
while True: while True:
line = input.readline() line = input.readline()
if len(line) == 0: if len(line) == 0:
...@@ -32,21 +37,26 @@ while True: ...@@ -32,21 +37,26 @@ while True:
declaration += line declaration += line
# Now look for a docstring. # Now look for a docstring.
docstringlines = [] docstringlines = []
line = input.readline() line = input.readline()
stripped = line.lstrip() l = line.strip()
if stripped.startswith('"""') or stripped.startswith("'''"): if l.startswith('"""') or l.startswith("'''"):
line = stripped[3:] if l.count('"""') == 2 or l.count("'''") == 2:
docstringlines.append(l[3:-3])
while line.find('"""') == -1 and line.find("'''") == -1: else:
docstringlines.append(line) docstringlines.append(l[3:])
line = input.readline().rstrip() line = input.readline()
if line.endswith('"""') or line.endswith("'''"): l = line.strip()
docstringlines.append(line[:-3]) while l.find('"""') == -1 and l.find("'''") == -1:
docstringlines.append(line.rstrip())
line = input.readline()
l = line.strip()
if line.rstrip().endswith('"""') or line.rstrip().endswith("'''"):
# last line
docstringlines.append(line.rstrip()[:-3])
docstring = NumpyDocString(cleandoc('\n'.join(docstringlines))) docstring = NumpyDocString(cleandoc('\n'.join(docstringlines)))
# print(docstringlines)
# Print out the docstring in Doxygen syntax, followed by the declaration. # Print out the docstring in Doxygen syntax, followed by the declaration.
for line in docstring['Summary']: for line in docstring['Summary']:
...@@ -63,7 +73,7 @@ while True: ...@@ -63,7 +73,7 @@ while True:
type = name type = name
print('{prefix}## @return ({type}) {descr}'.format(prefix=prefix, type=type, name=name, descr=''.join(descr))) print('{prefix}## @return ({type}) {descr}'.format(prefix=prefix, type=type, name=name, descr=''.join(descr)))
print(declaration) print(declaration, end='')
if len(docstringlines) == 0: if len(docstringlines) == 0:
print(line, end='') print(line, end='')
else: else:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment