summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/sphinxext/numpydoc.py23
1 files changed, 19 insertions, 4 deletions
diff --git a/doc/sphinxext/numpydoc.py b/doc/sphinxext/numpydoc.py
index 0abdc7bc0..707107daf 100644
--- a/doc/sphinxext/numpydoc.py
+++ b/doc/sphinxext/numpydoc.py
@@ -18,6 +18,7 @@ It will:
import os, re, pydoc
from docscrape_sphinx import get_doc_object, SphinxDocString
+from sphinx.util.compat import Directive
import inspect
def mangle_docstrings(app, what, name, obj, options, lines,
@@ -122,18 +123,32 @@ from docutils.statemachine import ViewList
def get_directive(name):
from docutils.parsers.rst import directives
try:
+ return directives.directive(name, None, None)[0]
+ except AttributeError:
+ pass
+ try:
# docutils 0.4
return directives._directives[name]
except (AttributeError, KeyError):
- pass
- try:
- return directives.directive(name, None, None)[0]
- except AttributeError:
raise RuntimeError("No directive named '%s' found" % name)
def wrap_mangling_directive(base_directive_name, objtype):
base_directive = get_directive(base_directive_name)
+ if inspect.isfunction(base_directive):
+ base_func = base_directive
+ class base_directive(Directive):
+ required_arguments = base_func.arguments[0]
+ optional_arguments = base_func.arguments[1]
+ final_argument_whitespace = base_func.arguments[2]
+ option_spec = base_func.options
+ has_content = base_func.content
+ def run(self):
+ return base_func(self.name, self.arguments, self.options,
+ self.content, self.lineno,
+ self.content_offset, self.block_text,
+ self.state, self.state_machine)
+
class directive(base_directive):
def run(self):
env = self.state.document.settings.env