Skip to content

Commit 5f7b225

Browse files
committed
Add config option for adding :toctree: on autosummary lists.
IPython uses some lists of class attributes and methods, but we don't generate separate doc pages for each entry, so Sphinx throws warnings about "toctree contains reference to nonexisting document". This adds a Sphinx option called 'numpydoc_class_members_toctree', defaulting to True, controlling whether the autosummary lists are generated with the :toctree: option. Setting it to False suppresses these warnings, but prevents the lists acting as tables of contents. Addresses issue gh-5.
1 parent 0d38eb3 commit 5f7b225

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

numpydoc/docscrape_sphinx.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@
1313

1414
class SphinxDocString(NumpyDocString):
1515
def __init__(self, docstring, config={}):
16-
self.use_plots = config.get('use_plots', False)
16+
# Subclasses seemingly do not call this.
1717
NumpyDocString.__init__(self, docstring, config=config)
1818

19+
def load_config(self, config):
20+
self.use_plots = config.get('use_plots', False)
21+
self.class_members_toctree = config.get('class_members_toctree', True)
22+
1923
# string conversion routines
2024
def _str_header(self, name, symbol='`'):
2125
return ['.. rubric:: ' + name, '']
@@ -117,8 +121,10 @@ def _str_member_list(self, name):
117121
others.append((param, param_type, desc))
118122

119123
if autosum:
120-
out += ['.. autosummary::', ' :toctree:', '']
121-
out += autosum
124+
out += ['.. autosummary::']
125+
if self.class_members_toctree:
126+
out += [' :toctree:']
127+
out += [''] + autosum
122128

123129
if others:
124130
maxlen_0 = max(3, max([len(x[0]) for x in others]))
@@ -233,17 +239,18 @@ def __str__(self, indent=0, func_role="obj"):
233239

234240
class SphinxFunctionDoc(SphinxDocString, FunctionDoc):
235241
def __init__(self, obj, doc=None, config={}):
236-
self.use_plots = config.get('use_plots', False)
242+
self.load_config(config)
237243
FunctionDoc.__init__(self, obj, doc=doc, config=config)
238244

239245
class SphinxClassDoc(SphinxDocString, ClassDoc):
240246
def __init__(self, obj, doc=None, func_doc=None, config={}):
241-
self.use_plots = config.get('use_plots', False)
247+
self.load_config(config)
242248
ClassDoc.__init__(self, obj, doc=doc, func_doc=None, config=config)
243249

244250
class SphinxObjDoc(SphinxDocString):
245251
def __init__(self, obj, doc=None, config={}):
246252
self._f = obj
253+
self.load_config(config)
247254
SphinxDocString.__init__(self, doc, config=config)
248255

249256
def get_doc_object(obj, what=None, doc=None, config={}):

numpydoc/numpydoc.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ def mangle_docstrings(app, what, name, obj, options, lines,
3838
reference_offset=[0]):
3939

4040
cfg = dict(use_plots=app.config.numpydoc_use_plots,
41-
show_class_members=app.config.numpydoc_show_class_members)
41+
show_class_members=app.config.numpydoc_show_class_members,
42+
class_members_toctree=app.config.numpydoc_class_members_toctree,
43+
)
4244

4345
if what == 'module':
4446
# Strip top title
@@ -114,6 +116,7 @@ def setup(app, get_doc_object_=get_doc_object):
114116
app.add_config_value('numpydoc_edit_link', None, False)
115117
app.add_config_value('numpydoc_use_plots', None, False)
116118
app.add_config_value('numpydoc_show_class_members', True, True)
119+
app.add_config_value('numpydoc_class_members_toctree', True, True)
117120

118121
# Extra mangling domains
119122
app.add_domain(NumpyPythonDomain)

0 commit comments

Comments
 (0)