[Numpy-svn] r6343 - trunk/doc/sphinxext

numpy-svn@scip... numpy-svn@scip...
Thu Feb 5 18:27:32 CST 2009


Author: ptvirtan
Date: 2009-02-05 18:27:08 -0600 (Thu, 05 Feb 2009)
New Revision: 6343

Modified:
   trunk/doc/sphinxext/docscrape.py
   trunk/doc/sphinxext/docscrape_sphinx.py
   trunk/doc/sphinxext/numpydoc.py
Log:
doc/numpydoc: work better together with Sphinx's  config option

Modified: trunk/doc/sphinxext/docscrape.py
===================================================================
--- trunk/doc/sphinxext/docscrape.py	2009-02-05 20:11:40 UTC (rev 6342)
+++ trunk/doc/sphinxext/docscrape.py	2009-02-06 00:27:08 UTC (rev 6343)
@@ -406,11 +406,13 @@
 
 
 class FunctionDoc(NumpyDocString):
-    def __init__(self, func, role='func'):
+    def __init__(self, func, role='func', doc=None):
         self._f = func
         self._role = role # e.g. "func" or "meth"
+        if doc is None:
+            doc = inspect.getdoc(func) or ''
         try:
-            NumpyDocString.__init__(self,inspect.getdoc(func) or '')
+            NumpyDocString.__init__(self, doc)
         except ValueError, e:
             print '*'*78
             print "ERROR: '%s' while parsing `%s`" % (e, self._f)
@@ -459,7 +461,7 @@
 
 
 class ClassDoc(NumpyDocString):
-    def __init__(self,cls,modulename='',func_doc=FunctionDoc):
+    def __init__(self,cls,modulename='',func_doc=FunctionDoc,doc=None):
         if not inspect.isclass(cls):
             raise ValueError("Initialise using a class. Got %r" % cls)
         self._cls = cls
@@ -470,8 +472,11 @@
         self._name = cls.__name__
         self._func_doc = func_doc
 
-        NumpyDocString.__init__(self, pydoc.getdoc(cls))
+        if doc is None:
+            doc = pydoc.getdoc(cls)
 
+        NumpyDocString.__init__(self, doc)
+
     @property
     def methods(self):
         return [name for name,func in inspect.getmembers(self._cls)

Modified: trunk/doc/sphinxext/docscrape_sphinx.py
===================================================================
--- trunk/doc/sphinxext/docscrape_sphinx.py	2009-02-05 20:11:40 UTC (rev 6342)
+++ trunk/doc/sphinxext/docscrape_sphinx.py	2009-02-06 00:27:08 UTC (rev 6343)
@@ -115,7 +115,7 @@
 class SphinxClassDoc(SphinxDocString, ClassDoc):
     pass
 
-def get_doc_object(obj, what=None):
+def get_doc_object(obj, what=None, doc=None):
     if what is None:
         if inspect.isclass(obj):
             what = 'class'
@@ -126,8 +126,11 @@
         else:
             what = 'object'
     if what == 'class':
-        return SphinxClassDoc(obj, '', func_doc=SphinxFunctionDoc)
+        return SphinxClassDoc(obj, '', func_doc=SphinxFunctionDoc, doc=doc)
     elif what in ('function', 'method'):
-        return SphinxFunctionDoc(obj, '')
+        return SphinxFunctionDoc(obj, '', doc=doc)
     else:
-        return SphinxDocString(pydoc.getdoc(obj))
+        if doc is None:
+            doc = pydoc.getdoc(obj)
+        return SphinxDocString(doc)
+

Modified: trunk/doc/sphinxext/numpydoc.py
===================================================================
--- trunk/doc/sphinxext/numpydoc.py	2009-02-05 20:11:40 UTC (rev 6342)
+++ trunk/doc/sphinxext/numpydoc.py	2009-02-06 00:27:08 UTC (rev 6343)
@@ -28,7 +28,7 @@
                               re.I|re.S)
         lines[:] = title_re.sub('', "\n".join(lines)).split("\n")
     else:
-        doc = get_doc_object(obj, what)
+        doc = get_doc_object(obj, what, "\n".join(lines))
         lines[:] = str(doc).split("\n")
 
     if app.config.numpydoc_edit_link and hasattr(obj, '__name__') and \



More information about the Numpy-svn mailing list