#196 Support Python 3.3

closed-fixed
nobody
None
5
2012-07-11
2012-07-08
Virgil Dupras
No

I'm fooling around with Python 3.3b1 and when I try to use Sphinx, I get the crash below. I'm told it might be docutils fault. Is there anything we can do about this?

{{{
# Sphinx version: 1.2pre
# Python version: 3.3.0b1
# Docutils version: 0.9.1 release
# Jinja2 version: 2.6
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/Sphinx-1.2predev_20120708-py3.3.egg/sphinx/cmdline.py", line 190, in main
app.build(force_all, filenames)
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/Sphinx-1.2predev_20120708-py3.3.egg/sphinx/application.py", line 204, in build
self.builder.build_update()
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/Sphinx-1.2predev_20120708-py3.3.egg/sphinx/builders/__init__.py", line 196, in build_update
'out of date' % len(to_build))
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/Sphinx-1.2predev_20120708-py3.3.egg/sphinx/builders/__init__.py", line 216, in build
purple, length):
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/Sphinx-1.2predev_20120708-py3.3.egg/sphinx/builders/__init__.py", line 120, in status_iterator
for item in iterable:
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/Sphinx-1.2predev_20120708-py3.3.egg/sphinx/environment.py", line 613, in update_generator
self.read_doc(docname, app=app)
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/Sphinx-1.2predev_20120708-py3.3.egg/sphinx/environment.py", line 756, in read_doc
pub.set_components(None, 'restructuredtext', None)
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/docutils-0.9.1-py3.3.egg/docutils/core.py", line 96, in set_components
self.reader.set_parser(parser_name)
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/docutils-0.9.1-py3.3.egg/docutils/readers/__init__.py", line 60, in set_parser
parser_class = parsers.get_parser_class(parser_name)
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/docutils-0.9.1-py3.3.egg/docutils/parsers/__init__.py", line 46, in get_parser_class
module = __import__(parser_name, globals(), locals())
File "<frozen importlib._bootstrap>", line 1294, in _find_and_load
File "<frozen importlib._bootstrap>", line 1258, in _find_and_load_unlocked
ImportError: No module named 'rst'
}}}

Discussion

  • Günter Milde
    Günter Milde
    2012-07-08

    Please note that Python 3.3 is not officially supported. Nevertheless we should prepare for it:

    does the following patch help?:

    Dir: /home/milde/Code/Python/docutils-svn/docutils/docutils/parsers/
    Index: __init__.py
    ===================================================================
    --- __init__.py (Revision 7462)
    +++ __init__.py (Arbeitskopie)
    @@ -8,6 +8,7 @@

    __docformat__ = 'reStructuredText'

    +import sys
    from docutils import Component

    @@ -43,5 +44,8 @@
    parser_name = parser_name.lower()
    if parser_name in _parser_aliases:
    parser_name = _parser_aliases[parser_name]
    - module = __import__(parser_name, globals(), locals())
    + if sys.version_info <= (2,4): # `level` arg missing
    + module = __import__(parser_name, globals(), locals())
    + else: # `level` arg required in Python >= 3.3
    + module = __import__(parser_name, globals(), locals(), level=1)
    return module.Parser

     
  • Virgil Dupras
    Virgil Dupras
    2012-07-09

    I tried applying the patch and it seems to help because the error I get is different:

    {{{
    # Sphinx version: 1.2pre
    # Python version: 3.3.0b1
    # Docutils version: 0.10 repository
    # Jinja2 version: 2.6
    Traceback (most recent call last):
    File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/Sphinx-1.2predev_20120709-py3.3.egg/sphinx/cmdline.py", line 190, in main
    app.build(force_all, filenames)
    File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/Sphinx-1.2predev_20120709-py3.3.egg/sphinx/application.py", line 204, in build
    self.builder.build_update()
    File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/Sphinx-1.2predev_20120709-py3.3.egg/sphinx/builders/__init__.py", line 196, in build_update
    'out of date' % len(to_build))
    File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/Sphinx-1.2predev_20120709-py3.3.egg/sphinx/builders/__init__.py", line 216, in build
    purple, length):
    File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/Sphinx-1.2predev_20120709-py3.3.egg/sphinx/builders/__init__.py", line 120, in status_iterator
    for item in iterable:
    File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/Sphinx-1.2predev_20120709-py3.3.egg/sphinx/environment.py", line 613, in update_generator
    self.read_doc(docname, app=app)
    File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/Sphinx-1.2predev_20120709-py3.3.egg/sphinx/environment.py", line 761, in read_doc
    pub.publish()
    File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/docutils/core.py", line 218, in publish
    self.apply_transforms()
    File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/docutils/core.py", line 199, in apply_transforms
    self.document.transformer.apply_transforms()
    File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/docutils/transforms/__init__.py", line 170, in apply_transforms
    transform = transform_class(self.document, startnode=pending)
    File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/docutils/transforms/__init__.py", line 56, in __init__
    document.settings.language_code, document.reporter)
    File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/docutils/languages/__init__.py", line 38, in get_language
    module = __import__('en', globals(), locals())
    File "<frozen importlib._bootstrap>", line 1294, in _find_and_load
    File "<frozen importlib._bootstrap>", line 1258, in _find_and_load_unlocked
    ImportError: No module named 'en'
    }}}

    I guess it's a matter of applying a similar change there too. I'll try that now.

     
  • Virgil Dupras
    Virgil Dupras
    2012-07-09

     
    Attachments
  • Virgil Dupras
    Virgil Dupras
    2012-07-09

    I ran a search/replace of all __import__() calls and replaced them with import_compat(), which I added in the utils module. I attached the patch as py33_import_fix.diff.

    I'm not familiar with docutils' coding standards, so I might have misplaced the function, but this patch makes Sphinx work alright with Python 3.3b1.

     
  • Günter Milde
    Günter Milde
    2012-07-11

    Thanks for the test and patch. A fix is now in the SVN repository.
    I used a somewhat different approach to make it easier to remove the compatibility hack once we drop support for Python 2.4.

     
  • Günter Milde
    Günter Milde
    2012-07-11

    • status: open --> closed-fixed