[Python-checkins] r63506 - doctools/trunk/sphinx/ext/ifconfig.py
georg.brandl
python-checkins at python.org
Tue May 20 16:41:26 CEST 2008
Author: georg.brandl
Date: Tue May 20 16:41:25 2008
New Revision: 63506
Log:
Better error reporting in ifconfig directive.
Modified:
doctools/trunk/sphinx/ext/ifconfig.py
Modified: doctools/trunk/sphinx/ext/ifconfig.py
==============================================================================
--- doctools/trunk/sphinx/ext/ifconfig.py (original)
+++ doctools/trunk/sphinx/ext/ifconfig.py Tue May 20 16:41:25 2008
@@ -29,6 +29,7 @@
def ifconfig_directive(name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine):
node = ifconfig()
+ node.line = lineno
node['expr'] = arguments[0]
state.nested_parse(content, content_offset, node)
return [node]
@@ -38,10 +39,21 @@
ns = app.config.__dict__.copy()
ns['builder'] = app.builder.name
for node in doctree.traverse(ifconfig):
- if not eval(node['expr'], ns):
- node.replace_self([])
+ try:
+ res = eval(node['expr'], ns)
+ except Exception, err:
+ # handle exceptions in a clean fashion
+ from traceback import format_exception_only
+ msg = ''.join(format_exception_only(err.__class__, err))
+ newnode = doctree.reporter.error('Exception occured in '
+ 'ifconfig expression: \n%s' %
+ msg, base_node=node)
+ node.replace_self(newnode)
else:
- node.replace_self(node.children)
+ if not res:
+ node.replace_self([])
+ else:
+ node.replace_self(node.children)
def setup(app):
More information about the Python-checkins
mailing list