Ticket #14005: 14005.diff

File 14005.diff, 7.3 KB (added by Ramiro Morales, 14 years ago)

Removes compatibility with Sphinx < 0.6

  • docs/_ext/djangodocs.py

    diff --git a/docs/_ext/djangodocs.py b/docs/_ext/djangodocs.py
    a b  
    1717import os
    1818import sphinx
    1919import sphinx.addnodes
    20 try:
    21     from sphinx import builders
    22 except ImportError:
    23     import sphinx.builder as builders
    24 try:
    25     import sphinx.builders.html as builders_html
    26 except ImportError:
    27     builders_html = builders
     20import sphinx.builders.html as html_builder
    2821from sphinx.util.console import bold
    2922import sphinx.directives
    3023import sphinx.environment
    31 try:
    32     import sphinx.writers.html as sphinx_htmlwriter
    33 except ImportError:
    34     import sphinx.htmlwriter as sphinx_htmlwriter
     24import sphinx.writers.html as sphinx_htmlwriter
    3525import sphinx.roles
    3626from docutils import nodes
    3727
     
    7464    app.add_transform(SuppressBlockquotes)
    7565    app.add_builder(DjangoStandaloneHTMLBuilder)
    7666
    77     # Monkeypatch PickleHTMLBuilder so that it doesn't die in Sphinx 0.4.2
    78     if sphinx.__version__ == '0.4.2':
    79         monkeypatch_pickle_builder()
    80 
    8167def parse_version_directive(name, arguments, options, content, lineno,
    8268                      content_offset, block_text, state, state_machine):
    8369    env = state.document.settings.env
     
    10692    env.note_versionchange(node['type'], node['version'], node, lineno)
    10793    return ret
    10894
    109                
     95
    11096class SuppressBlockquotes(docutils.transforms.Transform):
    11197    """
    11298    Remove the default blockquotes that encase indented list, tables, etc.
    11399    """
    114100    default_priority = 300
    115    
     101
    116102    suppress_blockquote_child_nodes = (
    117         docutils.nodes.bullet_list, 
    118         docutils.nodes.enumerated_list, 
     103        docutils.nodes.bullet_list,
     104        docutils.nodes.enumerated_list,
    119105        docutils.nodes.definition_list,
    120         docutils.nodes.literal_block, 
    121         docutils.nodes.doctest_block, 
    122         docutils.nodes.line_block, 
     106        docutils.nodes.literal_block,
     107        docutils.nodes.doctest_block,
     108        docutils.nodes.line_block,
    123109        docutils.nodes.table
    124110    )
    125    
     111
    126112    def apply(self):
    127113        for node in self.document.traverse(docutils.nodes.block_quote):
    128114            if len(node.children) == 1 and isinstance(node.children[0], self.suppress_blockquote_child_nodes):
     
    136122    # Don't use border=1, which docutils does by default.
    137123    def visit_table(self, node):
    138124        self.body.append(self.starttag(node, 'table', CLASS='docutils'))
    139    
     125
    140126    # <big>? Really?
    141127    def visit_desc_parameterlist(self, node):
    142128        self.body.append('(')
    143129        self.first_param = 1
    144    
     130
    145131    def depart_desc_parameterlist(self, node):
    146132        self.body.append(')')
    147         pass
    148        
     133
    149134    #
    150135    # Don't apply smartypants to literal blocks
    151136    #
     
    156141    def depart_literal_block(self, node):
    157142        sphinx_htmlwriter.SmartyPantsHTMLTranslator.depart_literal_block(self, node)
    158143        self.no_smarty -= 1
    159        
     144
    160145    #
    161     # Turn the "new in version" stuff (versoinadded/versionchanged) into a
     146    # Turn the "new in version" stuff (versionadded/versionchanged) into a
    162147    # better callout -- the Sphinx default is just a little span,
    163148    # which is a bit less obvious that I'd like.
    164149    #
    165150    # FIXME: these messages are all hardcoded in English. We need to change
    166151    # that to accomodate other language docs, but I can't work out how to make
    167     # that work and I think it'll require Sphinx 0.5 anyway.
     152    # that work.
    168153    #
    169154    version_text = {
    170155        'deprecated':       'Deprecated in Django %s',
    171156        'versionchanged':   'Changed in Django %s',
    172157        'versionadded':     'New in Django %s',
    173158    }
    174    
     159
    175160    def visit_versionmodified(self, node):
    176161        self.body.append(
    177162            self.starttag(node, 'div', CLASS=node['type'])
     
    181166            len(node) and ":" or "."
    182167        )
    183168        self.body.append('<span class="title">%s</span> ' % title)
    184    
     169
    185170    def depart_versionmodified(self, node):
    186171        self.body.append("</div>\n")
    187    
     172
    188173    # Give each section a unique ID -- nice for custom CSS hooks
    189     # This is different on docutils 0.5 vs. 0.4...
    190 
    191     if hasattr(sphinx_htmlwriter.SmartyPantsHTMLTranslator, 'start_tag_with_title') and sphinx.__version__ == '0.4.2':
    192         def start_tag_with_title(self, node, tagname, **atts):
    193             node = {
    194                 'classes': node.get('classes', []),
    195                 'ids': ['s-%s' % i for i in node.get('ids', [])]
    196             }
    197             return self.starttag(node, tagname, **atts)
    198 
    199     else:
    200         def visit_section(self, node):
    201             old_ids = node.get('ids', [])
    202             node['ids'] = ['s-' + i for i in old_ids]
    203             if sphinx.__version__ != '0.4.2':
    204                 node['ids'].extend(old_ids)
    205             sphinx_htmlwriter.SmartyPantsHTMLTranslator.visit_section(self, node)
    206             node['ids'] = old_ids
     174    def visit_section(self, node):
     175        old_ids = node.get('ids', [])
     176        node['ids'] = ['s-' + i for i in old_ids]
     177        node['ids'].extend(old_ids)
     178        sphinx_htmlwriter.SmartyPantsHTMLTranslator.visit_section(self, node)
     179        node['ids'] = old_ids
    207180
    208181def parse_django_admin_node(env, sig, signode):
    209182    command = sig.split(' ')[0]
     
    234207        raise ValueError
    235208    return firstname
    236209
    237 def monkeypatch_pickle_builder():
    238     import shutil
    239     from os import path
    240     try:
    241         import cPickle as pickle
    242     except ImportError:
    243         import pickle
    244    
    245     def handle_finish(self):
    246         # dump the global context
    247         outfilename = path.join(self.outdir, 'globalcontext.pickle')
    248         f = open(outfilename, 'wb')
    249         try:
    250             pickle.dump(self.globalcontext, f, 2)
    251         finally:
    252             f.close()
    253 
    254         self.info(bold('dumping search index...'))
    255         self.indexer.prune(self.env.all_docs)
    256         f = open(path.join(self.outdir, 'searchindex.pickle'), 'wb')
    257         try:
    258             self.indexer.dump(f, 'pickle')
    259         finally:
    260             f.close()
    261 
    262         # copy the environment file from the doctree dir to the output dir
    263         # as needed by the web app
    264         shutil.copyfile(path.join(self.doctreedir, builders.ENV_PICKLE_FILENAME),
    265                         path.join(self.outdir, builders.ENV_PICKLE_FILENAME))
    266 
    267         # touch 'last build' file, used by the web application to determine
    268         # when to reload its environment and clear the cache
    269         open(path.join(self.outdir, builders.LAST_BUILD_FILENAME), 'w').close()
    270 
    271     builders.PickleHTMLBuilder.handle_finish = handle_finish
    272 
    273 
    274 class DjangoStandaloneHTMLBuilder(builders_html.StandaloneHTMLBuilder):
     210class DjangoStandaloneHTMLBuilder(html_builder.StandaloneHTMLBuilder):
    275211    """
    276212    Subclass to add some extra things we need.
    277213    """
  • docs/internals/documentation.txt

    diff --git a/docs/internals/documentation.txt b/docs/internals/documentation.txt
    a b  
    1515To actually build the documentation locally, you'll currently need to install
    1616Sphinx -- ``easy_install Sphinx`` should do the trick.
    1717
     18.. note::
     19
     20    Generation of the Django documentation will work with Sphinx version 0.6
     21    or newer, but we recommend going straigh to Sphinx 1.0 or newer.
     22
    1823Then, building the html is easy; just ``make html`` from the ``docs`` directory.
    1924
    2025To get started contributing, you'll want to read the `ReStructuredText
Back to Top