Skip to content

Commit d701642

Browse files
lukelbdbsipocz
authored andcommitted
Add automodsumm_included_members option
1 parent 5e09fd5 commit d701642

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

sphinx_automodapi/automodapi.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
objects warnings.
6969
7070
71-
This extension also adds four sphinx configuration options:
71+
This extension also adds five sphinx configuration options:
7272
7373
* ``automodapi_inheritance_diagram``
7474
Should be a boolean that indicates whether to show inheritance diagrams
@@ -93,6 +93,12 @@
9393
Should be a bool and if ``True`` members that a class inherits from a base
9494
class are included in the generated documentation. Defaults to ``False``.
9595
96+
* ``automodsumm_included_members``
97+
A list of strings containing the names of hidden class members that should be
98+
included in the documentation. This is most commonly used to add special class
99+
methods like ``__getitem__`` and ``__setitem__``. Defaults to
100+
``['__init__', '__call__']``.
101+
96102
.. _automodule: http://sphinx-doc.org/latest/ext/autodoc.html?highlight=automodule#directive-automodule
97103
"""
98104

sphinx_automodapi/automodsumm.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
in the generated documentation. The flags ``:inherited-members:`` or
4747
``:no-inherited-members:`` allows overrriding this global setting.
4848
49-
This extension also adds two sphinx configuration options:
49+
This extension also adds three sphinx configuration options:
5050
5151
* ``automodsumm_writereprocessed``
5252
Should be a bool, and if ``True``, will cause `automodsumm`_ to write files
@@ -62,6 +62,12 @@ class members that are inherited from a base class. This value can be
6262
``:inherited-members:`` or ``:no-inherited-members:`` options. Defaults to
6363
``False``.
6464
65+
* ``automodsumm_included_members``
66+
A list of strings containing the names of hidden class members that should be
67+
included in the documentation. This is most commonly used to add special class
68+
methods like ``__getitem__`` and ``__setitem__``. Defaults to
69+
``['__init__', '__call__']``.
70+
6571
.. _sphinx.ext.autosummary: http://sphinx-doc.org/latest/ext/autosummary.html
6672
.. _autosummary: http://sphinx-doc.org/latest/ext/autosummary.html#directive-autosummary
6773
@@ -269,8 +275,8 @@ def process_automodsumm_generation(app):
269275
generate_automodsumm_docs(
270276
lines, sfn, app=app, builder=app.builder,
271277
base_path=app.srcdir,
272-
inherited_members=app.config.automodsumm_inherited_members)
273-
278+
inherited_members=app.config.automodsumm_inherited_members,
279+
included_members=app.config.automodsumm_included_members)
274280

275281
# _automodsummrex = re.compile(r'^(\s*)\.\. automodsumm::\s*([A-Za-z0-9_.]+)\s*'
276282
# r'\n\1(\s*)(\S|$)', re.MULTILINE)
@@ -406,7 +412,8 @@ def automodsumm_to_autosummary_lines(fn, app):
406412
def generate_automodsumm_docs(lines, srcfn, app=None, suffix='.rst',
407413
base_path=None, builder=None,
408414
template_dir=None,
409-
inherited_members=False):
415+
inherited_members=False,
416+
included_members=('__init__', '__call__')):
410417
"""
411418
This function is adapted from
412419
`sphinx.ext.autosummary.generate.generate_autosummmary_docs` to
@@ -581,11 +588,10 @@ def get_members_class(obj, typ, include_public=[],
581588
# use default value
582589
include_base = inherited_members
583590

584-
api_class_methods = ['__init__', '__call__']
585591
ns['members'] = get_members_class(obj, None,
586592
include_base=include_base)
587593
ns['methods'], ns['all_methods'] = \
588-
get_members_class(obj, 'method', api_class_methods,
594+
get_members_class(obj, 'method', included_members,
589595
include_base=include_base)
590596
ns['attributes'], ns['all_attributes'] = \
591597
get_members_class(obj, 'attribute',
@@ -664,6 +670,8 @@ def setup(app):
664670

665671
app.add_config_value('automodsumm_writereprocessed', False, True)
666672
app.add_config_value('automodsumm_inherited_members', False, 'env')
673+
app.add_config_value(
674+
'automodsumm_included_members', ['__init__', '__call__'], 'env')
667675

668676
return {'parallel_read_safe': True,
669677
'parallel_write_safe': True}

0 commit comments

Comments
 (0)