Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add automodsumm_included_members option, take2 #165

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion sphinx_automodapi/automodapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
objects warnings.


This extension also adds four sphinx configuration options:
This extension also adds five sphinx configuration options:

* ``automodapi_inheritance_diagram``
Should be a boolean that indicates whether to show inheritance diagrams
Expand All @@ -93,6 +93,12 @@
Should be a bool and if ``True`` members that a class inherits from a base
class are included in the generated documentation. Defaults to ``False``.

* ``automodsumm_included_members``
A list of strings containing the names of hidden class members that should be
included in the documentation. This is most commonly used to add special class
methods like ``__getitem__`` and ``__setitem__``. Defaults to
``['__init__', '__call__']``.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit confusing to document this option in the automodapi module. Some options are documented in both modules, some other are not ...

.. _automodule: http://sphinx-doc.org/latest/ext/autodoc.html?highlight=automodule#directive-automodule
"""

Expand Down
19 changes: 14 additions & 5 deletions sphinx_automodapi/automodsumm.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
in the generated documentation. The flags ``:inherited-members:`` or
``:no-inherited-members:`` allows overrriding this global setting.

This extension also adds two sphinx configuration options:
This extension also adds three sphinx configuration options:

* ``automodsumm_writereprocessed``
Should be a bool, and if ``True``, will cause `automodsumm`_ to write files
Expand All @@ -62,6 +62,12 @@ class members that are inherited from a base class. This value can be
``:inherited-members:`` or ``:no-inherited-members:`` options. Defaults to
``False``.

* ``automodsumm_included_members``
A list of strings containing the names of hidden class members that should be
included in the documentation. This is most commonly used to add special class
methods like ``__getitem__`` and ``__setitem__``. Defaults to
``['__init__', '__call__']``.

.. _sphinx.ext.autosummary: http://sphinx-doc.org/latest/ext/autosummary.html
.. _autosummary: http://sphinx-doc.org/latest/ext/autosummary.html#directive-autosummary

Expand Down Expand Up @@ -295,7 +301,8 @@ def process_automodsumm_generation(app):
generate_automodsumm_docs(
lines, sfn, app=app, builder=app.builder,
base_path=app.srcdir,
inherited_members=app.config.automodsumm_inherited_members)
inherited_members=app.config.automodsumm_inherited_members,
included_members=app.config.automodsumm_included_members)


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

api_class_methods = ['__init__', '__call__']
ns['members'] = get_members_class(obj, None,
include_base=include_base)
ns['methods'], ns['all_methods'] = \
get_members_class(obj, 'method', api_class_methods,
get_members_class(obj, 'method', included_members,
include_base=include_base)
ns['attributes'], ns['all_attributes'] = \
get_members_class(obj, 'attribute',
Expand Down Expand Up @@ -676,6 +683,8 @@ def setup(app):

app.add_config_value('automodsumm_writereprocessed', False, True)
app.add_config_value('automodsumm_inherited_members', False, 'env')
app.add_config_value(
'automodsumm_included_members', ['__init__', '__call__'], 'env')

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