diff options
author | Pauli Virtanen <pav@iki.fi> | 2009-07-22 01:22:41 +0000 |
---|---|---|
committer | Pauli Virtanen <pav@iki.fi> | 2009-07-22 01:22:41 +0000 |
commit | d8be0c2ce965d6e34b307cc4295b40fe3aa07859 (patch) | |
tree | 9bb0366ac323d116e524c086873b3567d208c703 /doc/sphinxext/numpydoc.py | |
parent | 2951b794d0b6498c5d6b2fd8c0f188a447bd8d14 (diff) | |
download | numpy-d8be0c2ce965d6e34b307cc4295b40fe3aa07859.tar.gz |
numpydoc: really fix docutils < 0.5
Diffstat (limited to 'doc/sphinxext/numpydoc.py')
-rw-r--r-- | doc/sphinxext/numpydoc.py | 23 |
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 |