Commit 04f68ba4 authored by Robert McGibbon's avatar Robert McGibbon
Browse files

Prettify some of the docstrings

parent 532f2bd6
%module openmm
%include "factory.i" %include "factory.i"
%include "std_string.i" %include "std_string.i"
%include "std_iostream.i" %include "std_iostream.i"
......
#!/usr/bin/env python #!/usr/bin/env python
# #
# #
"""Build swig imput file from xml encoded header files (see gccxml).""" """Build swig imput file from xml encoded header files (see gccxml)."""
__author__ = "Randall J. Radmer" __author__ = "Randall J. Radmer"
__version__ = "1.0" __version__ = "1.0"
import sys, os import sys, os
import time import time
import getopt import getopt
import re import re
import xml.etree.ElementTree as etree import xml.etree.ElementTree as etree
# try:
from html.parser import HTMLParser
except ImportError:
# python 2
from HTMLParser import HTMLParser
def striphtmltags(s):
"""Strip a couple html tags used inside docstrings in the C++ source
to produce something more easily read as plain text.
"""
class ConvertLists(HTMLParser):
def reset(self):
super(ConvertLists, self).reset()
self.out = []
def handle_starttag(self, tag, attrs):
if tag == 'li':
self.out.append('\n - ')
def handle_data(self, data):
self.out.append(data.strip())
convertlists = ConvertLists()
def replace_ul_tags(m):
a, b = m.span()
sub = s[a:b]
convertlists.reset()
convertlists.feed(sub)
return '\n%s\n\n' % ''.join(convertlists.out)
s = re.sub('\s*(<ul>.*</ul>\s*)', replace_ul_tags, s, flags=re.MULTILINE | re.DOTALL)
s = s.replace('<i>', '_')
s = s.replace('</i>', '_')
return s
INDENT = " "; INDENT = " ";
...@@ -83,7 +119,7 @@ def getClassMethodList(classNode, skipMethods): ...@@ -83,7 +119,7 @@ def getClassMethodList(classNode, skipMethods):
shortClassName=stripOpenmmPrefix(className) shortClassName=stripOpenmmPrefix(className)
methodList=[] methodList=[]
for section in findNodes(classNode, "sectiondef", kind="public-static-func")+findNodes(classNode, "sectiondef", kind="public-func"): for section in findNodes(classNode, "sectiondef", kind="public-static-func")+findNodes(classNode, "sectiondef", kind="public-func"):
for memberNode in findNodes(section, "memberdef", kind="function", prot="public"): for memberNode in findNodes(section, "memberdef", kind="function", prot="public"):
methDefinition = getText("definition", memberNode) methDefinition = getText("definition", memberNode)
shortMethDefinition=stripOpenmmPrefix(methDefinition) shortMethDefinition=stripOpenmmPrefix(methDefinition)
methName=shortMethDefinition.split()[-1] methName=shortMethDefinition.split()[-1]
...@@ -95,14 +131,14 @@ def getClassMethodList(classNode, skipMethods): ...@@ -95,14 +131,14 @@ def getClassMethodList(classNode, skipMethods):
sys.stderr.write("Warning: Including class %s\n" % sys.stderr.write("Warning: Including class %s\n" %
shortClassName) shortClassName)
continue continue
if (shortClassName, methName) in skipMethods: continue if (shortClassName, methName) in skipMethods: continue
# set template info # set template info
templateType = getText("templateparamlist/param/type", memberNode) templateType = getText("templateparamlist/param/type", memberNode)
templateName = getText("templateparamlist/param/declname", memberNode) templateName = getText("templateparamlist/param/declname", memberNode)
methodList.append( (shortClassName, methodList.append( (shortClassName,
memberNode, memberNode,
shortMethDefinition, shortMethDefinition,
...@@ -266,6 +302,7 @@ class SwigInputBuilder: ...@@ -266,6 +302,7 @@ class SwigInputBuilder:
dNode = classNode.find('detaileddescription') dNode = classNode.find('detaileddescription')
if dNode is not None: if dNode is not None:
docstring = getNodeText(dNode).strip().replace('"', '\\"') docstring = getNodeText(dNode).strip().replace('"', '\\"')
docstring = striphtmltags(docstring)
self.fOutDocstring.write('%%feature("docstring") %s "%s";\n' % (className, docstring)) self.fOutDocstring.write('%%feature("docstring") %s "%s";\n' % (className, docstring))
self.fOut.write("class %s" % className) self.fOut.write("class %s" % className)
if className in self.configModule.MISSING_BASE_CLASSES: if className in self.configModule.MISSING_BASE_CLASSES:
......
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