# HG changeset patch # User Sylvain Thénault # Date 1260804325 -3600 # Node ID 8a9a00a9405c9d7530c25c56bc460ec2dc7cf8c4 # Parent 3f8b7ffdda5356e0005c1bca755700fba7fb6356 quick and dirty fix trying to avoid rest directive conflicts when using sphinx (which seems to import the code) diff -r 3f8b7ffdda53 -r 8a9a00a9405c cwconfig.py --- a/cwconfig.py Mon Dec 14 15:35:21 2009 +0100 +++ b/cwconfig.py Mon Dec 14 16:25:25 2009 +0100 @@ -560,6 +560,15 @@ self.adjust_sys_path() self.load_defaults() self.translations = {} + # don't register ReStructured Text directives by simple import, avoid pb + # with eg sphinx. + # XXX should be done properly with a function from cw.uicfg + try: + from cubicweb.ext.rest import cw_rest_init + except ImportError: + pass + else: + cw_rest_init() def adjust_sys_path(self): self.cls_adjust_sys_path() diff -r 3f8b7ffdda53 -r 8a9a00a9405c ext/rest.py --- a/ext/rest.py Mon Dec 14 15:35:21 2009 +0100 +++ b/ext/rest.py Mon Dec 14 16:25:25 2009 +0100 @@ -80,8 +80,6 @@ return [nodes.reference(rawtext, utils.unescape(rest), refuri=ref, **options)], [] -register_canonical_role('eid', eid_reference_role) - def winclude_directive(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine): @@ -146,14 +144,13 @@ winclude_directive.arguments = (1, 0, 1) winclude_directive.options = {'literal': directives.flag, 'encoding': directives.encoding} -directives.register_directive('winclude', winclude_directive) try: from pygments import highlight from pygments.lexers import get_lexer_by_name, LEXERS from pygments.formatters import HtmlFormatter except ImportError: - pass + pygments_directive = None else: _PYGMENTS_FORMATTER = HtmlFormatter() @@ -174,7 +171,6 @@ pygments_directive.arguments = (1, 0, 1) pygments_directive.content = 1 - directives.register_directive('sourcecode', pygments_directive) class CubicWebReSTParser(Parser): @@ -244,3 +240,15 @@ data = unicode(data, encoding, 'replace') return xml_escape(req._('error while publishing ReST text') + '\n\n' + data) + + +_INITIALIZED = False +def cw_rest_init(): + global _INITIALIZED + if _INITIALIZED: + return + _INITIALIZED = True + register_canonical_role('eid', eid_reference_role) + directives.register_directive('winclude', winclude_directive) + if pygments_directive is not None: + directives.register_directive('sourcecode', pygments_directive)