From 9d48a39d23b507e18ca8fa7c5786b5eaea926d0e Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Fri, 13 Nov 2009 18:42:21 +0000 Subject: sphinxext: add numpydoc_show_class_members option (from Michael Droettboom) --- doc/sphinxext/docscrape.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'doc/sphinxext/docscrape.py') diff --git a/doc/sphinxext/docscrape.py b/doc/sphinxext/docscrape.py index 0e073da93..f36f7ceb7 100644 --- a/doc/sphinxext/docscrape.py +++ b/doc/sphinxext/docscrape.py @@ -84,7 +84,7 @@ class Reader(object): class NumpyDocString(object): - def __init__(self,docstring): + def __init__(self, docstring, config={}): docstring = textwrap.dedent(docstring).split('\n') self._doc = Reader(docstring) @@ -183,7 +183,7 @@ class NumpyDocString(object): return params - + _name_rgx = re.compile(r"^\s*(:(?P\w+):`(?P[a-zA-Z0-9_.-]+)`|" r" (?P[a-zA-Z0-9_.-]+))\s*", re.X) def _parse_see_also(self, content): @@ -216,7 +216,7 @@ class NumpyDocString(object): current_func = None rest = [] - + for line in content: if not line.strip(): continue @@ -258,7 +258,7 @@ class NumpyDocString(object): if len(line) > 2: out[line[1]] = strip_each_in(line[2].split(',')) return out - + def _parse_summary(self): """Grab signature (if given) and summary""" if self._is_at_section(): @@ -275,7 +275,7 @@ class NumpyDocString(object): if not self._is_at_section(): self['Extended Summary'] = self._read_to_next_section() - + def _parse(self): self._doc.reset() self._parse_summary() @@ -408,7 +408,7 @@ def header(text, style='-'): class FunctionDoc(NumpyDocString): - def __init__(self, func, role='func', doc=None): + def __init__(self, func, role='func', doc=None, config={}): self._f = func self._role = role # e.g. "func" or "meth" if doc is None: @@ -442,7 +442,7 @@ class FunctionDoc(NumpyDocString): else: func = self._f return func, func_name - + def __str__(self): out = '' @@ -463,7 +463,8 @@ class FunctionDoc(NumpyDocString): class ClassDoc(NumpyDocString): - def __init__(self,cls,modulename='',func_doc=FunctionDoc,doc=None): + def __init__(self, cls, doc=None, modulename='', func_doc=FunctionDoc, + config={}): if not inspect.isclass(cls): raise ValueError("Initialise using a class. Got %r" % cls) self._cls = cls @@ -479,12 +480,13 @@ class ClassDoc(NumpyDocString): NumpyDocString.__init__(self, doc) - if not self['Methods']: - self['Methods'] = [(name, '', '') for name in sorted(self.methods)] - - if not self['Attributes']: - self['Attributes'] = [(name, '', '') - for name in sorted(self.properties)] + if config.get('show_class_members', True): + if not self['Methods']: + self['Methods'] = [(name, '', '') + for name in sorted(self.methods)] + if not self['Attributes']: + self['Attributes'] = [(name, '', '') + for name in sorted(self.properties)] @property def methods(self): -- cgit v1.2.1