2121 sixu = lambda s : unicode (s , 'unicode_escape' )
2222
2323
24+ IMPORT_MATPLOTLIB_RE = r'\b(import +matplotlib|from +matplotlib +import)\b'
25+
26+
2427class SphinxDocString (NumpyDocString ):
2528 def __init__ (self , docstring , config = {}):
2629 NumpyDocString .__init__ (self , docstring , config = config )
@@ -88,10 +91,10 @@ def _str_returns(self, name='Returns'):
8891 out += ['' ]
8992 return out
9093
91- def _process_param (self , param , desc , autosum ):
94+ def _process_param (self , param , desc , fake_autosummary ):
9295 """Determine how to display a parameter
9396
94- Emulates autosummary behavior if autosum is not None.
97+ Emulates autosummary behavior if fake_autosummary
9598
9699 Parameters
97100 ----------
@@ -100,12 +103,9 @@ def _process_param(self, param, desc, autosum):
100103 desc : list of str
101104 The parameter description as given in the docstring. This is
102105 ignored when autosummary logic applies.
103- autosum : list or None
104- If a list , autosummary-style behaviour will apply for params
106+ fake_autosummary : bool
107+ If True , autosummary-style behaviour will apply for params
105108 that are attributes of the class and have a docstring.
106- Names for autosummary generation will be appended to this list.
107-
108- If None, autosummary is disabled.
109109
110110 Returns
111111 -------
@@ -128,7 +128,7 @@ def _process_param(self, param, desc, autosum):
128128 param = param .strip ()
129129 display_param = ('**%s**' if self .use_blockquotes else '%s' ) % param
130130
131- if autosum is None :
131+ if not fake_autosummary :
132132 return display_param , desc
133133
134134 param_obj = getattr (self ._obj , param , None )
@@ -150,7 +150,6 @@ def _process_param(self, param, desc, autosum):
150150 link_prefix = ''
151151
152152 # Referenced object has a docstring
153- autosum .append (" %s%s" % (autosum_prefix , param ))
154153 display_param = ':obj:`%s <%s%s>`' % (param ,
155154 link_prefix ,
156155 param )
@@ -190,15 +189,11 @@ def _str_param_list(self, name, fake_autosummary=False):
190189 """
191190 out = []
192191 if self [name ]:
193- if fake_autosummary :
194- autosum = []
195- else :
196- autosum = None
197-
198192 out += self ._str_field_list (name )
199193 out += ['' ]
200194 for param , param_type , desc in self [name ]:
201- display_param , desc = self ._process_param (param , desc , autosum )
195+ display_param , desc = self ._process_param (param , desc ,
196+ fake_autosummary )
202197
203198 if param_type :
204199 out += self ._str_indent (['%s : %s' % (display_param ,
@@ -211,14 +206,6 @@ def _str_param_list(self, name, fake_autosummary=False):
211206 out += self ._str_indent (desc , 8 )
212207 out += ['' ]
213208
214- if fake_autosummary and autosum :
215- if self .class_members_toctree :
216- autosum .insert (0 , ' :toctree:' )
217- autosum .insert (0 , '.. autosummary::' )
218- out += ['..' , ' HACK to make autogen generate docs:' ]
219- out += self ._str_indent (autosum , 4 )
220- out += ['' ]
221-
222209 return out
223210
224211 @property
@@ -348,7 +335,7 @@ def _str_references(self):
348335 def _str_examples (self ):
349336 examples_str = "\n " .join (self ['Examples' ])
350337
351- if (self .use_plots and 'import matplotlib' in examples_str
338+ if (self .use_plots and re . search ( IMPORT_MATPLOTLIB_RE , examples_str )
352339 and 'plot::' not in examples_str ):
353340 out = []
354341 out += self ._str_header ('Examples' )
0 commit comments