[Cubicweb] docutils broken with CubicWeb

Dimitri Papadopoulos Orfanos dimitri.papadopoulos at cea.fr
Mon Apr 11 16:08:29 CEST 2016


Dear Denis,

Thank you for testing on your side. Monkey patching still results in
crashes here, whatever we try.

After some more digging:

* While initializing our application cube (that is while initializing
site_cubicweb.py, entities.py or hooks.py) daemonize() has not been
called yet. Hence the initial current directory can be retrieved after all:
  	_docutils_initial_cwd = os.getcwd()

* We use docutils in a piece of code looking like this:
  	class CreateDocumentation(hook.Hook):
  	    """ On startup create the documentation.
  	    """
  	    __regid__ = "piws.create_documentation"
  	    events = ("server_startup", )

  	    def __call__(self):
  	        # >>>>> code using docutils <<<<<
The hook __call__ is called after daemonize() as far as I can see: the
current directory has changed to '/' when not in debug mode.

* Instead of monkey patching, I use the following hack to avoid crashes:
  	class CreateDocumentation(hook.Hook):
  	""" On startup create the documentation.
  	"""
  	__regid__ = "piws.create_documentation"
  	events = ("server_startup", )

  	def __call__(self):
  	    os.chdir(_docutils_initial_cwd)
  	    # >>>>> code using docutils <<<<<
Not very nice, but not worse than the docutils bug, and it works.

* The strange thing is that the following code, while nicer, results in
crashes:
  	class CreateDocumentation(hook.Hook):
  	""" On startup create the documentation.
  	"""
  	__regid__ = "piws.create_documentation"
  	events = ("server_startup", )

  	def __call__(self):
  	    current_cwd = os.getcwd()
  	    os.chdir(_docutils_initial_cwd)
  	    # >>>>> code using docutils <<<<<
  	    os.chdir(current_cwd)
It looks like docutils is somehow used elsewhere - but not directly in
our code.


Conclusion:

1. It would be nice if CubicWeb could work around the docutils bug.
Unfortunately monkey patching doesn't seem to be working for us and
would depend on the docutils version anyway. Our own fix above is just a
bad hack (we perform an os.chdir() back to the initial current directory).

2. The CubicWeb initialization process is too complicated.
Part of the code is executed before daemonize(), and another part of the
code is executed after daemonize(). I may be missing something, but I
cannot find documentation on the subject. Actually this shouldn't even
require documentation. All our application code should probably be run
*after* daemonize().

Best,
Dimitri

Le 07/04/2016 13:56, Denis Laxalde a écrit :
> I just tried:
> 
> site_cubicweb.py:
> 
> import os.path
> from docutils.writers import html4css1
> 
> html4css1.Writer.default_template_path = os.path.join(
>     os.path.dirname(html4css1.__file__), html4css1.Writer.default_template)
> 
> and then in, e.g., entities.py:
> 
> from cubicweb.ext.html4zope import CSS1Writer
> print(CSS1Writer.default_template_path)
> 
> 
> gives me the "monkeypatched" value (cubicweb.ext.html4zopeis the only
> place in cubicweb where I found the doctutils module at stake).

-- 
Dimitri Papadopoulos
CEA/Saclay
DRF, I2BM, NeuroSpin
F-91191 Gif-sur-Yvette cedex, France



More information about the Cubicweb mailing list