Documentation fails to build with Python 3 #115

Closed
Arfrever opened this Issue Apr 5, 2012 · 4 comments

Comments

Projects
None yet
4 participants

Arfrever commented Apr 5, 2012

Sphinx >=1.1 supports Python 3. docs/conf.py of Jinja specifies usage of jinjaext extension, which does not support Python 3. 2to3 generates changes sufficient for Python 3. Changes related to .next() / next() (in last hunk) should be made conditional on Python version.

$ PYTHONPATH="../build/lib" make html
sphinx-build -b html -d _build/doctrees   . _build/html
Running Sphinx v1.1.3
loading pickled environment... not yet created
building [html]: targets for 12 source files that are out of date
updating environment: 12 added, 0 changed, 0 removed
reading sources... [ 25%] extensions                                                                                                                         
Exception occurred:
  File "/tmp/jinja2/docs/jinjaext.py", line 148, in walk
    for key, name in node.__dict__.iteritems():
AttributeError: 'dict_proxy' object has no attribute 'iteritems'
The full traceback has been saved in /tmp/sphinx-err-z2mao4.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
Either send bugs to the mailing list at <http://groups.google.com/group/sphinx-dev/>,
or report them in the tracker at <http://bitbucket.org/birkenfeld/sphinx/issues/>. Thanks!
make: *** [html] Error 1
Owner

mitsuhiko commented Apr 6, 2012

I don't think this is the only problem with the docs on 3.x. I don't really have plans to make them compatible with 3.x at the moment, but feel free to provide patches.

mitsuhiko closed this Apr 6, 2012

Arfrever commented Apr 6, 2012

Please apply this patch:

--- docs/jinjaext.py
+++ docs/jinjaext.py
@@ -8,6 +8,7 @@
     :copyright: Copyright 2008 by Armin Ronacher.
     :license: BSD.
 """
+import collections
 import os
 import re
 import inspect
@@ -22,6 +23,7 @@ from pygments.style import Style
 from pygments.token import Keyword, Name, Comment, String, Error, \
      Number, Operator, Generic
 from jinja2 import Environment, FileSystemLoader
+from jinja2.utils import next


 def parse_rst(state, content_offset, doc):
@@ -110,10 +112,10 @@ def dump_functions(mapping):
     def directive(dirname, arguments, options, content, lineno,
                       content_offset, block_text, state, state_machine):
         reverse_mapping = {}
-        for name, func in mapping.iteritems():
+        for name, func in mapping.items():
             reverse_mapping.setdefault(func, []).append(name)
         filters = []
-        for func, names in reverse_mapping.iteritems():
+        for func, names in reverse_mapping.items():
             aliases = sorted(names, key=lambda x: len(x))
             name = aliases.pop()
             filters.append((name, aliases, func))
@@ -145,9 +147,9 @@ def jinja_nodes(dirname, arguments, options, content, lineno,
         doc.append(p + '.. autoclass:: %s(%s)' % (node.__name__, sig), '')
         if node.abstract:
             members = []
-            for key, name in node.__dict__.iteritems():
+            for key, name in node.__dict__.items():
                 if not key.startswith('_') and \
-                   not hasattr(node.__base__, key) and callable(name):
+                   not hasattr(node.__base__, key) and isinstance(name, collections.Callable):
                     members.append(key)
             if members:
                 members.sort()
@@ -169,10 +171,10 @@ def inject_toc(app, doctree, docname):
     titleiter = iter(doctree.traverse(nodes.title))
     try:
         # skip first title, we are not interested in that one
-        titleiter.next()
-        title = titleiter.next()
+        next(titleiter)
+        title = next(titleiter)
         # and check if there is at least another title
-        titleiter.next()
+        next(titleiter)
     except StopIteration:
         return
     tocnode = nodes.section('')

untitaker reopened this Mar 5, 2015

Owner

untitaker commented Mar 5, 2015

@techtonik Actually, this is a different issue. This is about building the docs under Py3, not the content itself. mitsuhiko#416

untitaker closed this Mar 5, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment