[Cubicweb] docutils broken with CubicWeb

Dimitri Papadopoulos Orfanos dimitri.papadopoulos at cea.fr
Thu Apr 7 03:20:15 CEST 2016

Dear all,

This is rather a docutils bug than a CubicWeb issue, but I thought you
might have suggestions how to best handle it.

There's a bug in docutils: the module defines and uses a
docutils.utils.relative_path() function to initialize (and later use)
paths as relative paths (relative to current dir). Of course
initializing and later using relative paths in a library is nonsensical
as a mere os.chdir() will break everything.

Example from docutils/writers/html4css1/__init__.py:
    class Writer(writers.Writer):
        default_stylesheet_path = utils.relative_path(
            os.path.join(os.getcwd(), 'dummy'),
            os.path.join(os.path.dirname(__file__), default_stylesheet))
This ugly code (what's "dummy" for?) initializes the class variable
"default_stylesheet_path" as soon as the module is imported.

The problem is that:
* CubicWeb itself imports docutils early on through a chain of imports,
* CubicWeb then calls daemonize(), except in debug mode, which in turn runs:
Whatever code uses docutils after that breaks the application silently,
without a single error message, except in debug mode!

This bug has been recently fixed in docutils:
Unfortunately it's not part of any formal release yet, so we're stuck
with it in the short term. Any clue how to best work around this issue
with minimal code modification? I would like to avoid modifying CubicWeb
(deferring imports maybe) or docutils (killing the ugly relative_path()
function wherever it's used with os.getcwd()).

=> How would you work around this from within a CubicWeb application?

Dimitri Papadopoulos
I2BM, NeuroSpin
91191 Gif-sur-Yvette cedex, France

More information about the Cubicweb mailing list