Skip to content

Commit 04947b6

Browse files
authored
Merge pull request #165 from bsipocz/unhide-class-methods
Add automodsumm_included_members option, take2
2 parents 57e934e + 033e007 commit 04947b6

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
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 & 5 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
@@ -295,7 +301,8 @@ def process_automodsumm_generation(app):
295301
generate_automodsumm_docs(
296302
lines, sfn, app=app, builder=app.builder,
297303
base_path=app.srcdir,
298-
inherited_members=app.config.automodsumm_inherited_members)
304+
inherited_members=app.config.automodsumm_inherited_members,
305+
included_members=app.config.automodsumm_included_members)
299306

300307

301308
# _automodsummrex = re.compile(r'^(\s*)\.\. automodsumm::\s*([A-Za-z0-9_.]+)\s*'
@@ -432,7 +439,8 @@ def automodsumm_to_autosummary_lines(fn, app):
432439
def generate_automodsumm_docs(lines, srcfn, app=None, suffix='.rst',
433440
base_path=None, builder=None,
434441
template_dir=None,
435-
inherited_members=False):
442+
inherited_members=False,
443+
included_members=('__init__', '__call__')):
436444
"""
437445
This function is adapted from
438446
`sphinx.ext.autosummary.generate.generate_autosummmary_docs` to
@@ -593,11 +601,10 @@ def get_members_class(obj, typ, include_public=[],
593601
# use default value
594602
include_base = inherited_members
595603

596-
api_class_methods = ['__init__', '__call__']
597604
ns['members'] = get_members_class(obj, None,
598605
include_base=include_base)
599606
ns['methods'], ns['all_methods'] = \
600-
get_members_class(obj, 'method', api_class_methods,
607+
get_members_class(obj, 'method', included_members,
601608
include_base=include_base)
602609
ns['attributes'], ns['all_attributes'] = \
603610
get_members_class(obj, 'attribute',
@@ -676,6 +683,8 @@ def setup(app):
676683

677684
app.add_config_value('automodsumm_writereprocessed', False, True)
678685
app.add_config_value('automodsumm_inherited_members', False, 'env')
686+
app.add_config_value(
687+
'automodsumm_included_members', ['__init__', '__call__'], 'env')
679688

680689
return {'parallel_read_safe': True,
681690
'parallel_write_safe': True}

0 commit comments

Comments
 (0)