Skip to content

Commit 5e6cbb0

Browse files
committed
Merge pull request #6 from takluyver/class_members_toctree-option
Add config option for adding :toctree: on autosummary lists.
2 parents 0d38eb3 + daa669d commit 5e6cbb0

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

README.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ The following options can be set in conf.py:
4040
Whether to show all members of a class in the Methods and Attributes
4141
sections automatically.
4242

43+
- numpydoc_class_members_toctree: bool
44+
45+
Whether to create a Sphinx table of contents for the lists of class
46+
methods and attributes. If a table of contents is made, Sphinx expects
47+
each entry to have a separate page.
48+
4349
- numpydoc_edit_link: bool (DEPRECATED -- edit your HTML template instead)
4450

4551
Whether to insert an edit link after docstrings.

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)