diff options
| author | Georg Brandl <georg@python.org> | 2010-01-07 19:07:50 +0100 |
|---|---|---|
| committer | Georg Brandl <georg@python.org> | 2010-01-07 19:07:50 +0100 |
| commit | f35d74d9cfa6c934b35af1e7e71efcbc63a3e3a5 (patch) | |
| tree | deb3ff63159b82b5d966600bf8c832cf8864f148 /sphinx/util | |
| parent | a5008da8ee1b8ada041851b390818714a67f0af2 (diff) | |
| parent | 0afca45dbc97654e489df0367bf92d9b4803cf78 (diff) | |
| download | sphinx-f35d74d9cfa6c934b35af1e7e71efcbc63a3e3a5.tar.gz | |
merge with trunk
Diffstat (limited to 'sphinx/util')
| -rw-r--r-- | sphinx/util/__init__.py | 25 | ||||
| -rw-r--r-- | sphinx/util/compat.py | 69 |
2 files changed, 29 insertions, 65 deletions
diff --git a/sphinx/util/__init__.py b/sphinx/util/__init__.py index b719b391..3ceafa5e 100644 --- a/sphinx/util/__init__.py +++ b/sphinx/util/__init__.py @@ -24,6 +24,8 @@ import traceback from os import path import docutils +from docutils import nodes + import sphinx # Errnos that we need. @@ -459,6 +461,20 @@ def split_explicit_title(text): return False, text, text +def make_refnode(builder, fromdocname, todocname, targetid, child, title=None): + """Shortcut to create a reference node.""" + node = nodes.reference('', '') + if fromdocname == todocname: + node['refid'] = targetid + else: + node['refuri'] = (builder.get_relative_uri(fromdocname, todocname) + + '#' + targetid) + if title: + node['reftitle'] = title + node.append(child) + return node + + # monkey-patch Node.traverse to get more speed # traverse() is called so many times during a build that it saves # on average 20-25% overall build time! @@ -488,8 +504,7 @@ def _new_traverse(self, condition=None, return self._old_traverse(condition, include_self, descend, siblings, ascend) -import docutils.nodes -docutils.nodes.Node._old_traverse = docutils.nodes.Node.traverse -docutils.nodes.Node._all_traverse = _all_traverse -docutils.nodes.Node._fast_traverse = _fast_traverse -docutils.nodes.Node.traverse = _new_traverse +nodes.Node._old_traverse = nodes.Node.traverse +nodes.Node._all_traverse = _all_traverse +nodes.Node._fast_traverse = _fast_traverse +nodes.Node.traverse = _new_traverse diff --git a/sphinx/util/compat.py b/sphinx/util/compat.py index 885a458e..3fbfe4b2 100644 --- a/sphinx/util/compat.py +++ b/sphinx/util/compat.py @@ -11,7 +11,7 @@ from docutils import nodes -# function missing in 0.5 SVN +# function missing in docutils 0.5 def make_admonition(node_class, name, arguments, options, content, lineno, content_offset, block_text, state, state_machine): #if not content: @@ -35,64 +35,13 @@ def make_admonition(node_class, name, arguments, options, content, lineno, return [admonition_node] -# support the class-style Directive interface even when using docutils 0.4 +# backwards-compatibility aliases for helpers in older Sphinx versions that +# supported the docutils 0.4 directive function interface -try: - from docutils.parsers.rst import Directive +from docutils.parsers.rst import Directive -except ImportError: - class Directive(object): - """ - Fake Directive class to allow Sphinx directives to be written in - class style. - """ - required_arguments = 0 - optional_arguments = 0 - final_argument_whitespace = False - option_spec = None - has_content = False - - def __init__(self, name, arguments, options, content, lineno, - content_offset, block_text, state, state_machine): - self.name = name - self.arguments = arguments - self.options = options - self.content = content - self.lineno = lineno - self.content_offset = content_offset - self.block_text = block_text - self.state = state - self.state_machine = state_machine - - def run(self): - raise NotImplementedError('Must override run() is subclass.') - - def directive_dwim(obj): - """ - Return something usable with register_directive(), regardless if - class or function. For that, we need to convert classes to a - function for docutils 0.4. - """ - if isinstance(obj, type) and issubclass(obj, Directive): - def _class_directive(name, arguments, options, content, - lineno, content_offset, block_text, - state, state_machine): - return obj(name, arguments, options, content, - lineno, content_offset, block_text, - state, state_machine).run() - _class_directive.options = obj.option_spec - _class_directive.content = obj.has_content - _class_directive.arguments = (obj.required_arguments, - obj.optional_arguments, - obj.final_argument_whitespace) - return _class_directive - return obj - -else: - def directive_dwim(obj): - """ - Return something usable with register_directive(), regardless if - class or function. Nothing to do here, because docutils 0.5 takes - care of converting functions itself. - """ - return obj +def directive_dwim(obj): + import warnings + warnings.warn('directive_dwim is deprecated and no longer needed', + DeprecationWarning, stacklevel=2) + return obj |
