[Python-checkins] r61799 - in doctools/trunk: CHANGES doc/ext/doctest.rst doc/intro.rst setup.py sphinx/directives.py sphinx/ext/autodoc.py sphinx/htmlwriter.py sphinx/util/compat.py

georg.brandl python-checkins at python.org
Sun Mar 23 16:07:16 CET 2008


Author: georg.brandl
Date: Sun Mar 23 16:07:15 2008
New Revision: 61799

Added:
   doctools/trunk/sphinx/util/compat.py
Modified:
   doctools/trunk/CHANGES
   doctools/trunk/doc/ext/doctest.rst
   doctools/trunk/doc/intro.rst
   doctools/trunk/setup.py
   doctools/trunk/sphinx/directives.py
   doctools/trunk/sphinx/ext/autodoc.py
   doctools/trunk/sphinx/htmlwriter.py
Log:
Make sphinx compatible with docutils SVN snapshots.


Modified: doctools/trunk/CHANGES
==============================================================================
--- doctools/trunk/CHANGES	(original)
+++ doctools/trunk/CHANGES	Sun Mar 23 16:07:15 2008
@@ -1,5 +1,7 @@
-Changes in trunk
-================
+Release 0.1.61798 (Mar 23, 2008)
+================================
+
+* sphinx: Work with docutils SVN snapshots as well as 0.4.
 
 * sphinx.ext.doctest: Make the group in which doctest blocks are
   placed selectable, and default to ``'default'``.

Modified: doctools/trunk/doc/ext/doctest.rst
==============================================================================
--- doctools/trunk/doc/ext/doctest.rst	(original)
+++ doctools/trunk/doc/ext/doctest.rst	Sun Mar 23 16:07:15 2008
@@ -77,7 +77,7 @@
    They will be respected when the test is run, but stripped from presentation
    output.
 
-   .. versionadded:: 0.2
+   .. versionadded:: 0.1.61798
       Removal of ``<BLANKLINE>`` and inline options in presentation output.
 
 

Modified: doctools/trunk/doc/intro.rst
==============================================================================
--- doctools/trunk/doc/intro.rst	(original)
+++ doctools/trunk/doc/intro.rst	Sun Mar 23 16:07:15 2008
@@ -17,8 +17,8 @@
 
 Sphinx needs at least **Python 2.4** to run.  If you like to have source code
 highlighting support, you must also install the Pygments_ library, which you can
-do via setuptools' easy_install.  Also, you need docutils version 0.4 (not some
-SVN trunk snapshot, because of incompatible API changes).
+do via setuptools' easy_install.  Sphinx should work with docutils version 0.4
+or some (not broken) SVN trunk snapshot.
 
 .. _reStructuredText: http://docutils.sf.net/rst.html
 .. _Pygments: http://pygments.org

Modified: doctools/trunk/setup.py
==============================================================================
--- doctools/trunk/setup.py	(original)
+++ doctools/trunk/setup.py	Sun Mar 23 16:07:15 2008
@@ -65,5 +65,5 @@
             'sphinx-quickstart = sphinx.quickstart:main'
         ]
     },
-    install_requires=['Pygments>=0.8', 'docutils==0.4']
+    install_requires=['Pygments>=0.8', 'docutils>=0.4']
 )

Modified: doctools/trunk/sphinx/directives.py
==============================================================================
--- doctools/trunk/sphinx/directives.py	(original)
+++ doctools/trunk/sphinx/directives.py	Sun Mar 23 16:07:15 2008
@@ -17,9 +17,9 @@
 
 from docutils import nodes
 from docutils.parsers.rst import directives
-from docutils.parsers.rst.directives import admonitions
 
 from sphinx import addnodes
+from sphinx.util.compat import make_admonition
 
 # ------ index markup --------------------------------------------------------------
 
@@ -446,7 +446,7 @@
 
 def seealso_directive(name, arguments, options, content, lineno,
                       content_offset, block_text, state, state_machine):
-    rv = admonitions.make_admonition(
+    rv = make_admonition(
         addnodes.seealso, name, ['See also'], options, content,
         lineno, content_offset, block_text, state, state_machine)
     return rv

Modified: doctools/trunk/sphinx/ext/autodoc.py
==============================================================================
--- doctools/trunk/sphinx/ext/autodoc.py	(original)
+++ doctools/trunk/sphinx/ext/autodoc.py	Sun Mar 23 16:07:15 2008
@@ -140,13 +140,13 @@
         indent += '   '
 
     # add docstring content
-    if what == 'module' and env.config.automodule_skip_lines:
+    if what == 'module' and env.config.automodule_skip_lines and docstring:
         docstring = '\n'.join(docstring.splitlines()
                               [env.config.automodule_skip_lines:])
 
     # get the encoding of the docstring
     module = getattr(todoc, '__module__', None)
-    if module is not None:
+    if module is not None and docstring is not None:
         docstring = docstring.decode(get_module_charset(module))
 
     docstring = prepare_docstring(docstring)

Modified: doctools/trunk/sphinx/htmlwriter.py
==============================================================================
--- doctools/trunk/sphinx/htmlwriter.py	(original)
+++ doctools/trunk/sphinx/htmlwriter.py	Sun Mar 23 16:07:15 2008
@@ -31,8 +31,10 @@
         self.output = visitor.astext()
         for attr in ('head_prefix', 'stylesheet', 'head', 'body_prefix',
                      'body_pre_docinfo', 'docinfo', 'body', 'fragment',
-                     'body_suffix'):
-            setattr(self, attr, getattr(visitor, attr))
+                     'body_suffix', 'meta', 'title', 'subtitle', 'header',
+                     'footer', 'html_prolog', 'html_head', 'html_title',
+                     'html_subtitle', 'html_body', ):
+            setattr(self, attr, getattr(visitor, attr, None))
 
 
 version_text = {
@@ -150,7 +152,7 @@
 
     # overwritten
     def visit_admonition(self, node, name=''):
-        self.body.append(self.start_tag_with_title(
+        self.body.append(self.starttag(
             node, 'div', CLASS=('admonition ' + name)))
         if name and name != 'seealso':
             node.insert(0, nodes.title(name, self.language.labels[name]))
@@ -161,8 +163,8 @@
     def depart_seealso(self, node):
         self.depart_admonition(node)
 
-    # overwritten
-    def visit_title(self, node, move_ids=1):
+    # overwritten (args/kwds due to docutils 0.4/0.5 incompatibility)
+    def visit_title(self, node, *args, **kwds):
         # if we have a section we do our own processing in order
         # to have ids in the hN-tags and not in additional a-tags
         if isinstance(node.parent, nodes.section):
@@ -174,7 +176,7 @@
             self.body.append(self.starttag(node, 'h%d' % h_level, '', **attrs))
             self.context.append('</h%d>\n' % h_level)
         else:
-            BaseTranslator.visit_title(self, node, move_ids)
+            BaseTranslator.visit_title(self, node, *args, **kwds)
 
     # overwritten
     def visit_literal_block(self, node):
@@ -264,6 +266,18 @@
     def depart_module(self, node):
         pass
 
+    # docutils 0.5 compatibility
+    def visit_note(self, node):
+        self.visit_admonition(node, 'note')
+    def depart_note(self, node):
+        self.depart_admonition(node)
+
+    # docutils 0.5 compatibility
+    def visit_warning(self, node):
+        self.visit_admonition(node, 'warning')
+    def depart_warning(self, node):
+        self.depart_admonition(node)
+
     # these are only handled specially in the SmartyPantsHTMLTranslator
     def visit_literal_emphasis(self, node):
         return self.visit_emphasis(node)

Added: doctools/trunk/sphinx/util/compat.py
==============================================================================
--- (empty file)
+++ doctools/trunk/sphinx/util/compat.py	Sun Mar 23 16:07:15 2008
@@ -0,0 +1,37 @@
+# -*- coding: utf-8 -*-
+"""
+    sphinx.util.compat
+    ~~~~~~~~~~~~~~~~~~
+
+    Stuff for docutils compatibility.
+
+    :copyright: 2008 by Georg Brandl.
+    :license: BSD.
+"""
+
+from docutils import nodes
+
+
+# function missing in 0.5 SVN
+def make_admonition(node_class, name, arguments, options, content, lineno,
+                    content_offset, block_text, state, state_machine):
+    if not content:
+        error = state_machine.reporter.error(
+            'The "%s" admonition is empty; content required.' % (name),
+            nodes.literal_block(block_text, block_text), line=lineno)
+        return [error]
+    text = '\n'.join(content)
+    admonition_node = node_class(text)
+    if arguments:
+        title_text = arguments[0]
+        textnodes, messages = state.inline_text(title_text, lineno)
+        admonition_node += nodes.title(title_text, '', *textnodes)
+        admonition_node += messages
+        if options.has_key('class'):
+            classes = options['class']
+        else:
+            classes = ['admonition-' + nodes.make_id(title_text)]
+        admonition_node['classes'] += classes
+    state.nested_parse(content, content_offset, admonition_node)
+    return [admonition_node]
+


More information about the Python-checkins mailing list