Skip to content

Commit 6f91d4a

Browse files
committed
GH-43: Add support for autosummary-nosignatures option.
1 parent e3a5be9 commit 6f91d4a

File tree

8 files changed

+136
-0
lines changed

8 files changed

+136
-0
lines changed

autodocsumm/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ def add_autosummary(self):
250250
self.add_line('', sourcename)
251251

252252
self.add_line('.. autosummary::', sourcename)
253+
if self.options.autosummary_nosignatures:
254+
self.add_line(' :nosignatures:', sourcename)
253255
self.add_line('', sourcename)
254256
indent = ' '
255257

@@ -280,6 +282,7 @@ class AutoSummModuleDocumenter(ModuleDocumenter, AutosummaryDocumenter):
280282
option_spec['autosummary-sections'] = list_option
281283
option_spec['autosummary-no-titles'] = bool_option
282284
option_spec['autosummary-force-inline'] = bool_option
285+
option_spec['autosummary-nosignatures'] = bool_option
283286

284287
#: Add options for members for the autosummary
285288
for _option in member_options.intersection(option_spec):
@@ -329,6 +332,7 @@ class AutoSummClassDocumenter(ClassDocumenter, AutosummaryDocumenter):
329332
option_spec['autosummary-sections'] = list_option
330333
option_spec['autosummary-no-titles'] = bool_option
331334
option_spec['autosummary-force-inline'] = bool_option
335+
option_spec['autosummary-nosignatures'] = bool_option
332336

333337
#: Add options for members for the autosummary
334338
for _option in member_options.intersection(option_spec):

docs/conf_settings.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ autosummary table (see the example in :ref:`summary-table-example`).
5656
``autosummary-force-inline``
5757
Force adding the autosummary, even it is already contained in the class
5858
or module docstring. See the example about :ref:`autosummary-position-example`
59+
``autosummary-nosignatures``
60+
Do not show function signatures in the summary table.
5961

6062

6163
.. _directives:

docs/examples.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,29 @@ which gives us
140140
:autosummary-no-nesting:
141141

142142

143+
.. _nosignatures-example:
144+
145+
Generating a summary table without signatures
146+
---------------------------------------------
147+
148+
Using the ``autosummary-nosignatures`` option, you can generate the
149+
autosummary table for a module that will not include function signatures.
150+
This is useful for giving a high-level overview of the function name and
151+
description. For the :doc:`demo module <demo_module>`, here's an example::
152+
153+
.. automodule:: dummy
154+
:members:
155+
:autosummary:
156+
:autosummary-nosignatures:
157+
158+
which gives us
159+
160+
.. automodule:: dummy
161+
:members:
162+
:autosummary:
163+
:autosummary-nosignatures:
164+
165+
143166
.. _select-sections-example:
144167

145168
Select the sections to document
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Autoclasssumm of Dummy Class without signatures
2+
===============================================
3+
4+
.. autoclasssumm:: dummy.TestClass
5+
:no-members:
6+
:autosummary-members:
7+
:autosummary-nosignatures:
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Automodulesumm of dummy test module without signatures
2+
======================================================
3+
4+
.. automodulesumm:: dummy
5+
:no-members:
6+
:autosummary-members:
7+
:autosummary-nosignatures:
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Dummy Class Doc without signatures
2+
==================================
3+
4+
.. autoclass:: dummy.TestClass
5+
:no-members:
6+
:autosummary-members:
7+
:autosummary-nosignatures:
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Docs of dummy test module without signatures
2+
============================================
3+
4+
.. automodule:: dummy
5+
:no-members:
6+
:autosummary-members:
7+
:autosummary-nosignatures:

tests/test_autodocsumm.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,22 @@ def test_module_with_title(self, app, status, warning):
185185
else:
186186
self.assertNotIn('Should also be skipped', html)
187187

188+
@with_app(buildername='html', srcdir=sphinx_supp,
189+
copy_srcdir_to_tmpdir=True)
190+
def test_module_nosignatures(self, app, status, warning):
191+
app.build()
192+
193+
html = get_html(app, 'test_module_nosignatures.html')
194+
self.assertIn('<span class="pre">TestClass</span>', html)
195+
self.assertIn('<span class="pre">test_func</span>', html)
196+
197+
# test whether the data is shown correctly
198+
self.assertIn('<span class="pre">large_data</span>', html)
199+
self.assertIn('<span class="pre">small_data</span>', html)
200+
201+
self.assertNotIn('<dt id="dummy.Class_CallTest">', html)
202+
self.assertNotIn('()', html)
203+
188204
@with_app(buildername='html', srcdir=sphinx_supp,
189205
copy_srcdir_to_tmpdir=True)
190206
def test_class(self, app, status, warning):
@@ -291,6 +307,34 @@ def test_class_summary_only(self, app, status, warning):
291307

292308
self.assertNotIn('<dt id="dummy.TestClass.small_data">', html)
293309

310+
@with_app(buildername='html', srcdir=sphinx_supp,
311+
copy_srcdir_to_tmpdir=True)
312+
def test_class_nosignatures(self, app, status, warning):
313+
app.build()
314+
html = get_html(app, '/test_class_nosignatures.html')
315+
316+
if sphinx_version[:2] > [3, 1]:
317+
self.assertIn(
318+
'<span class="pre">instance_attribute</span>',
319+
html)
320+
elif sphinx_version[:2] < [3, 1]:
321+
self.assertIn(
322+
'<span class="pre">dummy.TestClass.instance_attribute</span>',
323+
html)
324+
325+
self.assertIn('<span class="pre">test_method</span>', html)
326+
self.assertIn('<span class="pre">test_attr</span>', html)
327+
328+
# test whether the right objects are included
329+
self.assertIn('<span class="pre">class_caller</span>', html)
330+
331+
# test whether the data is shown correctly
332+
self.assertIn('<span class="pre">large_data</span>', html)
333+
self.assertIn('<span class="pre">small_data</span>', html)
334+
335+
self.assertNotIn('<dt id="dummy.TestClass.small_data">', html)
336+
self.assertNotIn('()', html)
337+
294338
@with_app(buildername='html', srcdir=sphinx_supp,
295339
copy_srcdir_to_tmpdir=True)
296340
def test_inherited(self, app, status, warning):
@@ -381,6 +425,23 @@ def test_autoclasssumm_some_sections(self, app, status, warning):
381425
self.assertIn('<span class="pre">class_caller</span>', html)
382426
self.assertIn('<span class="pre">test_attr</span>', html)
383427

428+
@with_app(buildername='html', srcdir=sphinx_supp,
429+
copy_srcdir_to_tmpdir=True)
430+
def test_autoclasssumm_nosignatures(self, app, status, warning):
431+
"""Test building the autosummary of a class without signatures."""
432+
app.build()
433+
434+
html = get_html(app, '/test_autoclasssumm_nosignatures.html')
435+
436+
# the class docstring must not be in the html
437+
self.assertNotIn("Class test for autosummary", html)
438+
439+
# test if the methods and attributes are there in a table
440+
self.assertIn('<span class="pre">test_method</span>', html)
441+
self.assertIn('<span class="pre">test_attr</span>', html)
442+
443+
self.assertNotIn('()', html)
444+
384445
@with_app(buildername='html', srcdir=sphinx_supp,
385446
copy_srcdir_to_tmpdir=True)
386447
def test_automodulesumm(self, app, status, warning):
@@ -413,6 +474,24 @@ def test_automodulesumm_some_sections(self, app, status, warning):
413474
self.assertIn('<span class="pre">large_data</span>', html)
414475
self.assertIn('<span class="pre">test_func</span>', html)
415476

477+
@with_app(buildername='html', srcdir=sphinx_supp,
478+
copy_srcdir_to_tmpdir=True)
479+
def test_automodulesumm_nosignatures(self, app, status, warning):
480+
"""Test building the autosummary of a module without signatures."""
481+
app.build()
482+
483+
html = get_html(app, '/test_automodulesumm_nosignatures.html')
484+
485+
# the class docstring must not be in the html
486+
self.assertNotIn("Module for testing the autodocsumm", html)
487+
488+
# test if the classes, data and functions are there in a table
489+
self.assertIn('<span class="pre">Class_CallTest</span>', html)
490+
self.assertIn('<span class="pre">large_data</span>', html)
491+
self.assertIn('<span class="pre">test_func</span>', html)
492+
493+
self.assertNotIn('()', html)
494+
416495
@with_app(buildername='html', srcdir=sphinx_supp,
417496
copy_srcdir_to_tmpdir=True)
418497
def test_empty(self, app, status, warning):

0 commit comments

Comments
 (0)