Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 12b65a5

Browse files
committed
Add ignore_emptydoc global option and flags
1 parent 4c8e33c commit 12b65a5

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

sphinx_automodapi/automodapi.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,15 @@
5454
The global sphinx configuration option
5555
``automodsumm_inherited_members`` decides if members that a class
5656
inherits from a base class are included in the generated
57-
documentation. The option ``:inherited-members:`` or ``:no-inherited-members:``
58-
allows the user to overrride the global setting.
57+
documentation. The flags ``:inherited-members:`` or ``:no-inherited-members:``
58+
allow the user to overrride the global setting.
59+
60+
* ``:ignore-emptydoc:`` or ``:no-ignore-emptydoc:``
61+
The global sphinx configuration option ``automodsumm_ignore_emptydoc``
62+
decides if functions, classes, and class methods with empty
63+
``__doc__`` attributes are included in the generated documentation. The flags
64+
``:ignore-emptydoc:`` or ``:no-ignore-emptydoc:`` allow the user to override
65+
the global setting.
5966
6067
6168
This extension also adds four sphinx configuration options:
@@ -241,7 +248,7 @@ def automodapi_replace(sourcestr, app, dotoctree=True, docname=None,
241248

242249
# look for actual options
243250
unknownops = []
244-
inherited_members = None
251+
inherited_members = ignore_emptydoc = None
245252
for opname, args in _automodapiargsrex.findall(spl[grp * 3 + 2]):
246253
if opname == 'skip':
247254
toskip.append(args.strip())
@@ -261,6 +268,10 @@ def automodapi_replace(sourcestr, app, dotoctree=True, docname=None,
261268
inherited_members = True
262269
elif opname == 'no-inherited-members':
263270
inherited_members = False
271+
elif opname == 'ignore-emptydoc':
272+
ignore_emptydoc = True
273+
elif opname == 'no-ignore-emptydoc':
274+
ignore_emptydoc = False
264275
elif opname == 'include-all-objects':
265276
allowothers = True
266277
else:
@@ -322,6 +333,10 @@ def automodapi_replace(sourcestr, app, dotoctree=True, docname=None,
322333
clsfuncoptions.append(':skip: ' + ','.join(toskip))
323334
if allowedpkgnms:
324335
clsfuncoptions.append(allowedpkgnms)
336+
if ignore_emptydoc is True:
337+
clsfuncoptions.append(':ignore-emptydoc:')
338+
if ignore_emptydoc is False:
339+
clsfuncoptions.append(':no-ignore-emptydoc:')
325340
if hascls: # This makes no sense unless there are classes.
326341
if inherited_members is True:
327342
clsfuncoptions.append(':inherited-members:')

sphinx_automodapi/automodsumm.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,14 @@
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+
* ``:ignore-emptydoc:`` or ``:no-ignore-emptydoc:``
50+
The global sphinx configuration option ``automodsumm_ignore_emptydoc``
51+
decides if functions, classes, and class methods with empty
52+
``__doc__`` attributes are included in the generated documentation. The flags
53+
``:ignore-emptydoc:`` or ``:no-ignore-emptydoc:`` allows overrriding this
54+
global setting.
55+
56+
This extension also adds three sphinx configuration options:
5057
5158
* ``automodsumm_writereprocessed``
5259
Should be a bool, and if ``True``, will cause `automodsumm`_ to write files
@@ -56,12 +63,19 @@
5663
cause of sphinx warnings or other debugging. Defaults to ``False``.
5764
5865
* ``automodsumm_inherited_members``
59-
Should be a bool and if ``True``, will cause `automodsumm`_ to document
66+
Should be a bool, and if ``True``, will cause `automodsumm`_ to document
6067
class members that are inherited from a base class. This value can be
6168
overriden for any particular automodsumm directive by including the
6269
``:inherited-members:`` or ``:no-inherited-members:`` options. Defaults to
6370
``False``.
6471
72+
* ``automodsumm_ignore_emptydoc``
73+
Should be a bool, and if ``True``, will cause `automodsumm`_ to ignore
74+
functions, classes, and class methods with empty ``__doc__`` attributes.
75+
This value can be overridden for any particular automodsumm directive by including
76+
the ``:ignore-emptydoc:`` or ``:no-ignore-emptydoc:`` options. Defaults to
77+
``False``.
78+
6579
.. _sphinx.ext.autosummary: http://sphinx-doc.org/latest/ext/autosummary.html
6680
.. _autosummary: http://sphinx-doc.org/latest/ext/autosummary.html#directive-autosummary
6781
@@ -124,6 +138,8 @@ class Automodsumm(Autosummary):
124138
option_spec['allowed-package-names'] = _str_list_converter
125139
option_spec['inherited-members'] = flag
126140
option_spec['no-inherited-members'] = flag
141+
option_spec['ignore-emptydoc'] = flag
142+
option_spec['no-ignore-emptydoc'] = flag
127143

128144
def run(self):
129145
env = self.state.document.settings.env
@@ -269,6 +285,7 @@ def process_automodsumm_generation(app):
269285
generate_automodsumm_docs(
270286
lines, sfn, app=app, builder=app.builder,
271287
suffix=suffix, base_path=app.srcdir,
288+
ignore_emptydoc=app.config.automodsumm_ignore_emptydoc,
272289
inherited_members=app.config.automodsumm_inherited_members)
273290

274291

@@ -408,6 +425,7 @@ def automodsumm_to_autosummary_lines(fn, app):
408425
def generate_automodsumm_docs(lines, srcfn, app=None, suffix='.rst',
409426
base_path=None, builder=None,
410427
template_dir=None,
428+
ignore_emptydoc=False,
411429
inherited_members=False):
412430
"""
413431
This function is adapted from
@@ -557,6 +575,12 @@ def get_members_class(obj, typ, include_public=[],
557575
documenter = get_documenter(app, safe_getattr(obj, name), obj)
558576
except AttributeError:
559577
continue
578+
if (
579+
ignore_emptydoc
580+
and documenter.objtype in ('method', 'class', 'function')
581+
and not getattr(safe_getattr(obj, name), '__doc__', '')
582+
):
583+
continue
560584
if typ is None or documenter.objtype == typ:
561585
items.append(name)
562586
elif typ == 'attribute' and documenter.objtype == 'property':
@@ -667,6 +691,7 @@ def setup(app):
667691

668692
app.add_config_value('automodsumm_writereprocessed', False, True)
669693
app.add_config_value('automodsumm_inherited_members', False, 'env')
694+
app.add_config_value('automodsumm_ignore_emptydoc', False, 'env')
670695

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

0 commit comments

Comments
 (0)