Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.0.X] Fixed #10539 -- Updated Sphinx configuration to accommodate 0…

….6 while retaining compatibility with 0.4 and 0.5. Thanks to Ramiro Morales for the patch.

Merge of r11162 from trunk.


git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@11165 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 4aca3be925e56db3c97331e3a32f9dd21df1cdc1 1 parent f538e15
Russell Keith-Magee authored July 03, 2009
53  docs/_ext/djangodocs.py
@@ -6,10 +6,16 @@
6 6
 import docutils.transforms
7 7
 import sphinx
8 8
 import sphinx.addnodes
9  
-import sphinx.builder
  9
+try:
  10
+    from sphinx import builders
  11
+except ImportError:
  12
+    import sphinx.builder as builders
10 13
 import sphinx.directives
11 14
 import sphinx.environment
12  
-import sphinx.htmlwriter
  15
+try:
  16
+    import sphinx.writers.html as sphinx_htmlwriter
  17
+except ImportError:
  18
+    import sphinx.htmlwriter as sphinx_htmlwriter
13 19
 
14 20
 def setup(app):
15 21
     app.add_crossref_type(
@@ -42,7 +48,7 @@ def setup(app):
42 48
         directivename = "django-admin-option",
43 49
         rolename      = "djadminopt",
44 50
         indextemplate = "pair: %s; django-admin command-line option",
45  
-        parse_node    = lambda env, sig, signode: sphinx.directives.parse_option_desc(signode, sig),
  51
+        parse_node    = parse_django_adminopt_node,
46 52
     )
47 53
     app.add_transform(SuppressBlockquotes)
48 54
     
@@ -71,7 +77,7 @@ def apply(self):
71 77
             if len(node.children) == 1 and isinstance(node.children[0], self.suppress_blockquote_child_nodes):
72 78
                 node.replace_self(node.children[0])
73 79
 
74  
-class DjangoHTMLTranslator(sphinx.htmlwriter.SmartyPantsHTMLTranslator):
  80
+class DjangoHTMLTranslator(sphinx_htmlwriter.SmartyPantsHTMLTranslator):
75 81
     """
76 82
     Django-specific reST to HTML tweaks.
77 83
     """
@@ -94,10 +100,10 @@ def depart_desc_parameterlist(self, node):
94 100
     #
95 101
     def visit_literal_block(self, node):
96 102
         self.no_smarty += 1
97  
-        sphinx.htmlwriter.SmartyPantsHTMLTranslator.visit_literal_block(self, node)
98  
-        
  103
+        sphinx_htmlwriter.SmartyPantsHTMLTranslator.visit_literal_block(self, node)
  104
+
99 105
     def depart_literal_block(self, node):
100  
-        sphinx.htmlwriter.SmartyPantsHTMLTranslator.depart_literal_block(self, node) 
  106
+        sphinx_htmlwriter.SmartyPantsHTMLTranslator.depart_literal_block(self, node)
101 107
         self.no_smarty -= 1
102 108
         
103 109
     #
@@ -131,7 +137,7 @@ def depart_versionmodified(self, node):
131 137
     # Give each section a unique ID -- nice for custom CSS hooks
132 138
     # This is different on docutils 0.5 vs. 0.4...
133 139
 
134  
-    if hasattr(sphinx.htmlwriter.SmartyPantsHTMLTranslator, 'start_tag_with_title') and sphinx.__version__ == '0.4.2':
  140
+    if hasattr(sphinx_htmlwriter.SmartyPantsHTMLTranslator, 'start_tag_with_title') and sphinx.__version__ == '0.4.2':
135 141
         def start_tag_with_title(self, node, tagname, **atts):
136 142
             node = {
137 143
                 'classes': node.get('classes', []), 
@@ -145,7 +151,7 @@ def visit_section(self, node):
145 151
             node['ids'] = ['s-' + i for i in old_ids]
146 152
             if sphinx.__version__ != '0.4.2':
147 153
                 node['ids'].extend(old_ids)
148  
-            sphinx.htmlwriter.SmartyPantsHTMLTranslator.visit_section(self, node)
  154
+            sphinx_htmlwriter.SmartyPantsHTMLTranslator.visit_section(self, node)
149 155
             node['ids'] = old_ids
150 156
 
151 157
 def parse_django_admin_node(env, sig, signode):
@@ -155,6 +161,25 @@ def parse_django_admin_node(env, sig, signode):
155 161
     signode += sphinx.addnodes.desc_name(title, title)
156 162
     return sig
157 163
 
  164
+def parse_django_adminopt_node(env, sig, signode):
  165
+    """A copy of sphinx.directives.CmdoptionDesc.parse_signature()"""
  166
+    from sphinx import addnodes
  167
+    from sphinx.directives.desc import option_desc_re
  168
+    count = 0
  169
+    firstname = ''
  170
+    for m in option_desc_re.finditer(sig):
  171
+        optname, args = m.groups()
  172
+        if count:
  173
+            signode += addnodes.desc_addname(', ', ', ')
  174
+        signode += addnodes.desc_name(optname, optname)
  175
+        signode += addnodes.desc_addname(args, args)
  176
+        if not count:
  177
+            firstname = optname
  178
+        count += 1
  179
+    if not firstname:
  180
+        raise ValueError
  181
+    return firstname
  182
+
158 183
 def monkeypatch_pickle_builder():
159 184
     import shutil
160 185
     from os import path
@@ -183,12 +208,12 @@ def handle_finish(self):
183 208
 
184 209
         # copy the environment file from the doctree dir to the output dir
185 210
         # as needed by the web app
186  
-        shutil.copyfile(path.join(self.doctreedir, sphinx.builder.ENV_PICKLE_FILENAME),
187  
-                        path.join(self.outdir, sphinx.builder.ENV_PICKLE_FILENAME))
  211
+        shutil.copyfile(path.join(self.doctreedir, builders.ENV_PICKLE_FILENAME),
  212
+                        path.join(self.outdir, builders.ENV_PICKLE_FILENAME))
188 213
 
189 214
         # touch 'last build' file, used by the web application to determine
190 215
         # when to reload its environment and clear the cache
191  
-        open(path.join(self.outdir, sphinx.builder.LAST_BUILD_FILENAME), 'w').close()
  216
+        open(path.join(self.outdir, builders.LAST_BUILD_FILENAME), 'w').close()
  217
+
  218
+    builders.PickleHTMLBuilder.handle_finish = handle_finish
192 219
 
193  
-    sphinx.builder.PickleHTMLBuilder.handle_finish = handle_finish
194  
-    
2  docs/_templates/layout.html
... ...
@@ -1,6 +1,6 @@
1 1
 {% extends "!layout.html" %}
2 2
 
3  
-{%- macro secondnav %}
  3
+{%- macro secondnav() %}
4 4
   {%- if prev %}
5 5
     &laquo; <a href="{{ prev.link|e }}" title="{{ prev.title|e }}">previous</a> 
6 6
     {{ reldelim2 }}

0 notes on commit 4aca3be

Please sign in to comment.
Something went wrong with that request. Please try again.