Edgewall Software

Opened 11 years ago

Last modified 11 years ago

#11248 closed defect

reST rendering can fail for TracStandalone — at Initial Version

Reported by: Ryan J Ollos Owned by:
Priority: normal Milestone: 0.12.6
Component: wiki system Version: 0.12-stable
Severity: normal Keywords: rest docutils restructuredtext
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description

Rendering WikiRestructuredText can fail with the following error in the log (comment:8:ticket:12245):

2013-07-17 17:30:05,613 Trac[api] WARNING: HTML preview using ReStructuredTextRenderer failed:
Traceback (most recent call last):
  File "/home/user/Workspace/t11245-2.7/teo-rjollos2.git/trac/mimeview/api.py", line 773, in render
    rendered_content, filename, url)
  File "/home/user/Workspace/t11245-2.7/teo-rjollos2.git/trac/mimeview/rst.py", line 278, in render
    'warning_stream': False})
  File "/home/user/Workspace/t11245-2.7/local/lib/python2.7/site-packages/docutils-0.10-py2.7.egg/docutils/core.py", line 448, in publish_parts
    enable_exit_status=enable_exit_status)
  File "/home/user/Workspace/t11245-2.7/local/lib/python2.7/site-packages/docutils-0.10-py2.7.egg/docutils/core.py", line 657, in publish_programmatically
    pub.set_components(reader_name, parser_name, writer_name)
  File "/home/user/Workspace/t11245-2.7/local/lib/python2.7/site-packages/docutils-0.10-py2.7.egg/docutils/core.py", line 93, in set_components
    self.set_reader(reader_name, self.parser, parser_name)
  File "/home/user/Workspace/t11245-2.7/local/lib/python2.7/site-packages/docutils-0.10-py2.7.egg/docutils/core.py", line 82, in set_reader
    reader_class = readers.get_reader_class(reader_name)
  File "/home/user/Workspace/t11245-2.7/local/lib/python2.7/site-packages/docutils-0.10-py2.7.egg/docutils/readers/__init__.py", line 113, in get_reader_class
    return module.Reader
AttributeError: 'module' object has no attribute 'Reader'

The problem is with line 110 in docutils/readers/__init__.py (DocUtils version 0.10):

module = __import__(reader_name, globals(), locals(), level=0)

Since by default the module name is specified as reader_name = 'standalone', this can result in the import of <module 'standalone' from './trac/web/standalone.pyc'>.

The issue can be resolved by explicitly specifying the default reader:

  • trac/mimeview/rst.py

    diff --git a/trac/mimeview/rst.py b/trac/mimeview/rst.py
    index bce5cac..f7ce83b 100644
    a b try:  
    2929    from docutils import nodes
    3030    from docutils.core import publish_parts
    3131    from docutils.parsers import rst
     32    from docutils.readers import standalone
    3233    from docutils import __version__
    3334    has_docutils = True
    3435except ImportError:
    class ReStructuredTextRenderer(Component):  
    270271        inliner.trac = (self.env, context)
    271272        parser = rst.Parser(inliner=inliner)
    272273        content = content_to_unicode(self.env, content, mimetype)
     274        # Explicitly specifying the default Reader is a workaround for #11248
    273275        parts = publish_parts(content, writer=writer, parser=parser,
     276                              reader=standalone.Reader(parser),
    274277                              settings_overrides={'halt_level': 6,
    275278                                                  'warning_stream': False,
    276279                                                  'file_insertion_enabled': 0,

The lastest DocUtils version is 0.10, released in December 2012. The issue has been fixed in [7646], [7648] but the fix has not yet been incorporated into a formal release, and we'd need to support earlier versions of DocUtils anyway, so I propose to apply the workaround in 1.0-stable.

Change History (0)

Note: See TracTickets for help on using tickets.