Ticket #13616: 13616_3.diff

File 13616_3.diff, 5.2 KB (added by Ramiro Morales, 14 years ago)

Path fixing all Sphinx 1.0 compatibility quirks

  • docs/_ext/djangodocs.py

    diff -r 18f3582d965e docs/_ext/djangodocs.py
    a b  
    8888    if not is_nextversion:
    8989        if len(arguments) == 1:
    9090            linktext = 'Please, see the release notes <releases-%s>' % (arguments[0])
    91             xrefs = sphinx.roles.xfileref_role('ref', linktext, linktext, lineno, state)
     91            try:
     92                xrefs = sphinx.roles.XRefRole()('ref', linktext, linktext, lineno, state) # Sphinx >= 1.0
     93            except:
     94                xrefs = sphinx.roles.xfileref_role('ref', linktext, linktext, lineno, state) # Sphinx < 1.0
    9295            node.extend(xrefs[0])
    9396        node['version'] = arguments[0]
    9497    else:
     
    100103        if content:
    101104            state.nested_parse(content, content_offset, node)
    102105        ret = ret + messages
    103     env.note_versionchange(node['type'], node['version'], node, lineno)
     106    if sphinx.__version__ >= '1.0':
     107        env.versionchanges.setdefault(node['version'], []).append(
     108            (node['type'], env.temp_data['docname'], lineno,
     109            env.temp_data.get('py_module'),
     110            env.temp_data.get('object'),
     111            node.astext()))
     112    else:
     113        env.note_versionchange(node['type'], node['version'], node, lineno)
    104114    return ret
    105115
    106                
     116
    107117class SuppressBlockquotes(docutils.transforms.Transform):
    108118    """
    109119    Remove the default blockquotes that encase indented list, tables, etc.
    110120    """
    111121    default_priority = 300
    112    
     122
    113123    suppress_blockquote_child_nodes = (
    114         docutils.nodes.bullet_list, 
    115         docutils.nodes.enumerated_list, 
     124        docutils.nodes.bullet_list,
     125        docutils.nodes.enumerated_list,
    116126        docutils.nodes.definition_list,
    117         docutils.nodes.literal_block, 
    118         docutils.nodes.doctest_block, 
    119         docutils.nodes.line_block, 
     127        docutils.nodes.literal_block,
     128        docutils.nodes.doctest_block,
     129        docutils.nodes.line_block,
    120130        docutils.nodes.table
    121131    )
    122    
     132
    123133    def apply(self):
    124134        for node in self.document.traverse(docutils.nodes.block_quote):
    125135            if len(node.children) == 1 and isinstance(node.children[0], self.suppress_blockquote_child_nodes):
     
    133143    # Don't use border=1, which docutils does by default.
    134144    def visit_table(self, node):
    135145        self.body.append(self.starttag(node, 'table', CLASS='docutils'))
    136    
     146
    137147    # <big>? Really?
    138148    def visit_desc_parameterlist(self, node):
    139149        self.body.append('(')
    140150        self.first_param = 1
    141    
     151
    142152    def depart_desc_parameterlist(self, node):
    143153        self.body.append(')')
    144154        pass
    145        
     155
    146156    #
    147157    # Don't apply smartypants to literal blocks
    148158    #
     
    153163    def depart_literal_block(self, node):
    154164        sphinx_htmlwriter.SmartyPantsHTMLTranslator.depart_literal_block(self, node)
    155165        self.no_smarty -= 1
    156        
     166
    157167    #
    158168    # Turn the "new in version" stuff (versoinadded/versionchanged) into a
    159169    # better callout -- the Sphinx default is just a little span,
    160170    # which is a bit less obvious that I'd like.
    161171    #
    162     # FIXME: these messages are all hardcoded in English. We need to chanage
     172    # FIXME: these messages are all hardcoded in English. We need to change
    163173    # that to accomodate other language docs, but I can't work out how to make
    164174    # that work and I think it'll require Sphinx 0.5 anyway.
    165175    #
     
    168178        'versionchanged':   'Changed in Django %s',
    169179        'versionadded':     'New in Django %s',
    170180    }
    171    
     181
    172182    def visit_versionmodified(self, node):
    173183        self.body.append(
    174184            self.starttag(node, 'div', CLASS=node['type'])
     
    178188            len(node) and ":" or "."
    179189        )
    180190        self.body.append('<span class="title">%s</span> ' % title)
    181    
     191
    182192    def depart_versionmodified(self, node):
    183193        self.body.append("</div>\n")
    184    
     194
    185195    # Give each section a unique ID -- nice for custom CSS hooks
    186196    # This is different on docutils 0.5 vs. 0.4...
    187197
    188198    if hasattr(sphinx_htmlwriter.SmartyPantsHTMLTranslator, 'start_tag_with_title') and sphinx.__version__ == '0.4.2':
    189199        def start_tag_with_title(self, node, tagname, **atts):
    190200            node = {
    191                 'classes': node.get('classes', []), 
     201                'classes': node.get('classes', []),
    192202                'ids': ['s-%s' % i for i in node.get('ids', [])]
    193203            }
    194204            return self.starttag(node, tagname, **atts)
     
    212222def parse_django_adminopt_node(env, sig, signode):
    213223    """A copy of sphinx.directives.CmdoptionDesc.parse_signature()"""
    214224    from sphinx import addnodes
    215     from sphinx.directives.desc import option_desc_re
     225    try:
     226        from sphinx.domains.std import option_desc_re # Sphinx >= 1.0
     227    except:
     228        from sphinx.directives.desc import option_desc_re # Sphinx < 1.0
    216229    count = 0
    217230    firstname = ''
    218231    for m in option_desc_re.finditer(sig):
     
    235248        import cPickle as pickle
    236249    except ImportError:
    237250        import pickle
    238    
     251
    239252    def handle_finish(self):
    240253        # dump the global context
    241254        outfilename = path.join(self.outdir, 'globalcontext.pickle')
Back to Top