autosummary includes module attributes

This commit is contained in:
Daniel Fremont 2020-04-12 10:58:22 -07:00
parent f978490dfe
commit adbf5e6de3
2 changed files with 26 additions and 0 deletions

View File

@ -197,6 +197,21 @@ def generate_autosummary_content(name: str, obj: Any, parent: Any,
get_members(obj, {'class'}, imported=imported_members) get_members(obj, {'class'}, imported=imported_members)
ns['exceptions'], ns['all_exceptions'] = \ ns['exceptions'], ns['all_exceptions'] = \
get_members(obj, {'exception'}, imported=imported_members) get_members(obj, {'exception'}, imported=imported_members)
# Find module attributes with docstrings
attrs, public = [], []
from sphinx.pycode import ModuleAnalyzer, PycodeError
try:
analyzer = ModuleAnalyzer.for_module(name)
attr_docs = analyzer.find_attr_docs()
for _, attr_name in attr_docs:
if attr_name in ns['members']:
attrs.append(attr_name)
if not attr_name.startswith('_'):
public.append(attr_name)
except PycodeError as err:
pass
ns['attributes'], ns['all_attributes'] = attrs, public
elif doc.objtype == 'class': elif doc.objtype == 'class':
ns['members'] = dir(obj) ns['members'] = dir(obj)
ns['inherited_members'] = \ ns['inherited_members'] = \

View File

@ -2,6 +2,17 @@
.. automodule:: {{ fullname }} .. automodule:: {{ fullname }}
{% block attributes %}
{% if attributes %}
.. rubric:: Module Attributes
.. autosummary::
{% for item in attributes %}
{{item}}
{%- endfor %}
{% endif %}
{% endblock %}
{% block functions %} {% block functions %}
{% if functions %} {% if functions %}
.. rubric:: Functions .. rubric:: Functions