6262#: Options of the :class:`sphinx.ext.autodoc.ModuleDocumenter` that have an
6363#: effect on the selection of members for the documentation
6464member_options = {
65- 'members' , 'undoc-members' , 'inherited-members' , 'exlude -members' ,
65+ 'members' , 'undoc-members' , 'inherited-members' , 'exclude -members' ,
6666 'private-members' , 'special-members' , 'imported-members' ,
6767 'ignore-module-all' }
6868
@@ -208,6 +208,7 @@ class AutoSummModuleDocumenter(ModuleDocumenter, AutosummaryDocumenter):
208208 #: but with additional autosummary boolean option
209209 option_spec = ModuleDocumenter .option_spec .copy ()
210210 option_spec ['autosummary' ] = bool_option
211+ option_spec ['autosummary-no-nesting' ] = bool_option
211212
212213 #: Add options for members for the autosummary
213214 for _option in member_options .intersection (option_spec ):
@@ -244,6 +245,7 @@ class AutoSummClassDocumenter(ClassDocumenter, AutosummaryDocumenter):
244245 #: but with additional autosummary boolean option
245246 option_spec = ClassDocumenter .option_spec .copy ()
246247 option_spec ['autosummary' ] = bool_option
248+ option_spec ['autosummary-no-nesting' ] = bool_option
247249
248250 #: Add options for members for the autosummary
249251 for _option in member_options .intersection (option_spec ):
@@ -399,10 +401,10 @@ class AutoSummDirective(AutodocDirective, Autosummary):
399401
400402 if sphinx_version < [1 , 7 ]:
401403 _default_flags = AutodocDirective ._default_flags .union (
402- {'autosummary' } | set (map ('autosummary-{}' .format , member_options ))
404+ {'autosummary' , 'autosummary-no-nesting' } | set (map ('autosummary-{}' .format , member_options ))
403405 )
404406 else :
405- AUTODOC_DEFAULT_OPTIONS .append ( 'autosummary' )
407+ AUTODOC_DEFAULT_OPTIONS .extend ([ 'autosummary' , 'autosummary-no-nesting' ] )
406408 AUTODOC_DEFAULT_OPTIONS .extend (
407409 map ('autosummary-{}' .format , member_options ))
408410
@@ -463,7 +465,8 @@ def run(self):
463465 self .result = ViewList ()
464466 documenter = self .autosummary_documenter
465467 grouped_documenters = documenter .get_grouped_documenters ()
466- summ_nodes = self .autosumm_nodes (documenter , grouped_documenters )
468+ nested = 'autosummary-no-nesting' not in self .options
469+ summ_nodes = self .autosumm_nodes (documenter , grouped_documenters , nested )
467470
468471 dn = summ_nodes .pop (documenter .fullname )
469472 if self .name == 'automodule' :
@@ -559,7 +562,7 @@ def inject_summary(node):
559562 inject_summary (node )
560563 return doc_nodes
561564
562- def autosumm_nodes (self , documenter , grouped_documenters ):
565+ def autosumm_nodes (self , documenter , grouped_documenters , nested ):
563566 """Create the autosummary nodes based on the documenter content
564567
565568 Parameters
@@ -570,6 +573,8 @@ def autosumm_nodes(self, documenter, grouped_documenters):
570573 grouped_documenters: dict
571574 The dictionary as it is returned from the
572575 :meth:`AutosummaryDocumenter.get_grouped_documenters` method
576+ nested: bool
577+ If true, autosummary tables will also be created for members.
573578
574579 Returns
575580 -------
@@ -596,13 +601,14 @@ def autosumm_nodes(self, documenter, grouped_documenters):
596601 ViewList (['**%s**' % section ]), 0 , node )
597602 this_nodes += node
598603 this_nodes += self .get_table (items )
599- for mdocumenter , check_module in documenters :
600- if (mdocumenter .objtype == 'class' and
601- not (check_module and not mdocumenter .check_module ())):
602- if hasattr (mdocumenter , 'get_grouped_documenters' ):
603- summ_nodes .update (self .autosumm_nodes (
604- mdocumenter , mdocumenter .get_grouped_documenters ())
605- )
604+ if nested :
605+ for mdocumenter , check_module in documenters :
606+ if (mdocumenter .objtype == 'class' and
607+ not (check_module and not mdocumenter .check_module ())):
608+ if hasattr (mdocumenter , 'get_grouped_documenters' ):
609+ summ_nodes .update (self .autosumm_nodes (
610+ mdocumenter , mdocumenter .get_grouped_documenters (), nested )
611+ )
606612 summ_nodes [documenter .fullname ] = this_nodes
607613 return summ_nodes
608614
@@ -781,12 +787,12 @@ def setup(app):
781787 CallableAttributeDocumenter , NoDataDataDocumenter ,
782788 NoDataAttributeDocumenter ]:
783789 if not issubclass (registry .get (cls .objtype ), cls ):
784- try :
785- # we use add_documenter because this does not add a new
786- # directive
787- app .add_documenter (cls )
788- except AttributeError :
790+ if sphinx_version >= [2 , 2 ]:
791+ app .add_autodocumenter (cls , override = True )
792+ elif sphinx_version >= [0 , 6 ]:
789793 app .add_autodocumenter (cls )
794+ else :
795+ app .add_documenter (cls )
790796
791797 # directives
792798 if sphinx_version >= [1 , 8 ]:
0 commit comments