# How to display URL addresses: 'footnote', 'no', or 'inline'.
#texinfo_show_urls = 'footnote'
+
+empty_attr_summary = re.compile(r'\.\. rubric:: Attributes Summary\s*\.\. autosummary::\s*\.\. rubric::')
+empty_attr_documentation = re.compile(r'\.\. rubric:: Attributes Documentation\s*\.\. rubric::')
+
+def cleanup_source(app, docname, source):
+ """ Cleans up source files generated by automodapi. """
+ # Don't cleanup anything beside automodapi-generated sources.
+ if not automodapi_toctreedirnm in docname:
+ return
+ processed = source[0]
+
+ # Don't show the list of inheritance info as there is no inheritance in the
+ # SBI API. This avoids all the repeated text on all doc pages that a
+ # class inherits from 'object'.
+
+ processed = processed.replace(":show-inheritance:", "")
+ # Remove the SWIG generated 'thisown' attribute. It just bloats the generated
+ # documentation and users shouldn't fiddle with the value anyway.
+ processed = re.sub(r'~SB[a-zA-Z]+\.thisown', "", processed)
+ processed = processed.replace(" .. autoattribute:: thisown", "")
+
+ # After removing 'thisown', many objects don't have any attributes left.
+ # Remove all now empty attribute summary/documentation sections with
+ # some rather ugly regex.
+ processed = empty_attr_summary.sub('.. rubric::', processed)
+ processed = empty_attr_documentation.sub('.. rubric::', processed)
+
+ # Replace the original source with the processed one (source is a single
+ # element list).
+ source[0] = processed
+
+def setup(app):
+ app.connect('source-read', cleanup_source)