From 692f3f65acd441995f893908d694b3891a67070c Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Sat, 27 Jun 2009 15:02:14 +0000 Subject: docs: generate Attributes and Methods sections in class documentation --- doc/sphinxext/docscrape.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'doc/sphinxext/docscrape.py') diff --git a/doc/sphinxext/docscrape.py b/doc/sphinxext/docscrape.py index f374b3ddc..3e190b6f2 100644 --- a/doc/sphinxext/docscrape.py +++ b/doc/sphinxext/docscrape.py @@ -8,7 +8,7 @@ import re import pydoc from StringIO import StringIO from warnings import warn -4 + class Reader(object): """A line-based string reader. @@ -386,6 +386,8 @@ class NumpyDocString(object): out += self._str_see_also(func_role) for s in ('Notes','References','Examples'): out += self._str_section(s) + for param_list in ('Attributes', 'Methods'): + out += self._str_param_list(param_list) out += self._str_index() return '\n'.join(out) -- cgit v1.2.1 From aa292318e92eee5f99fa5701e4a84ae7bd0bdc4c Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Sat, 27 Jun 2009 17:40:32 +0000 Subject: docs: fill in stub Methods/Attributes sections if they are omitted --- doc/sphinxext/docscrape.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'doc/sphinxext/docscrape.py') diff --git a/doc/sphinxext/docscrape.py b/doc/sphinxext/docscrape.py index 3e190b6f2..0e073da93 100644 --- a/doc/sphinxext/docscrape.py +++ b/doc/sphinxext/docscrape.py @@ -479,21 +479,19 @@ 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)] + @property def methods(self): return [name for name,func in inspect.getmembers(self._cls) if not name.startswith('_') and callable(func)] - def __str__(self): - out = '' - out += super(ClassDoc, self).__str__() - out += "\n\n" - - #for m in self.methods: - # print "Parsing `%s`" % m - # out += str(self._func_doc(getattr(self._cls,m), 'meth')) + '\n\n' - # out += '.. index::\n single: %s; %s\n\n' % (self._name, m) - - return out - - + @property + def properties(self): + return [name for name,func in inspect.getmembers(self._cls) + if not name.startswith('_') and func is None] -- cgit v1.2.1