Show More
@@ -0,0 +1,4 b'' | |||
|
1 | IPython directive warnings | |
|
2 | -------------------------- | |
|
3 | ||
|
4 | The IPython directive now uses Sphinx logging for warnings. |
@@ -200,6 +200,7 b' from io import StringIO' | |||
|
200 | 200 | # Third-party |
|
201 | 201 | from docutils.parsers.rst import directives |
|
202 | 202 | from docutils.parsers.rst import Directive |
|
203 | from sphinx.util import logging | |
|
203 | 204 | |
|
204 | 205 | # Our own |
|
205 | 206 | from traitlets.config import Config |
@@ -556,16 +557,19 b' class EmbeddedSphinxShell(object):' | |||
|
556 | 557 | if self.directive.state: |
|
557 | 558 | filename = self.directive.state.document.current_source |
|
558 | 559 | lineno = self.directive.state.document.current_line |
|
560 | ||
|
561 | # Use sphinx logger for warnings | |
|
562 | logger = logging.getLogger(__name__) | |
|
559 | 563 | |
|
560 | 564 | # output any exceptions raised during execution to stdout |
|
561 | 565 | # unless :okexcept: has been specified. |
|
562 | 566 | if not is_okexcept and (("Traceback" in processed_output) or ("SyntaxError" in processed_output)): |
|
563 | s = "\nException in %s at block ending on line %s\n" % (filename, lineno) | |
|
567 | s = '\n>>>' + ('-' * 73) + '\n' | |
|
568 | s += "Exception in %s at block ending on line %s\n" % (filename, lineno) | |
|
564 | 569 | s += "Specify :okexcept: as an option in the ipython:: block to suppress this message\n" |
|
565 | sys.stdout.write('\n\n>>>' + ('-' * 73)) | |
|
566 | sys.stdout.write(s) | |
|
567 | sys.stdout.write(processed_output) | |
|
568 | sys.stdout.write('<<<' + ('-' * 73) + '\n\n') | |
|
570 | s += processed_output + "\n" | |
|
571 | s += "<<<" + ("-" * 73) | |
|
572 | logger.warning(s) | |
|
569 | 573 | if self.warning_is_error: |
|
570 | 574 | raise RuntimeError('Non Expected exception in `{}` line {}'.format(filename, lineno)) |
|
571 | 575 | |
@@ -573,15 +577,14 b' class EmbeddedSphinxShell(object):' | |||
|
573 | 577 | # unless :okwarning: has been specified. |
|
574 | 578 | if not is_okwarning: |
|
575 | 579 | for w in ws: |
|
576 | s = "\nWarning in %s at block ending on line %s\n" % (filename, lineno) | |
|
580 | s = '\n>>>' + ('-' * 73) + '\n' | |
|
581 | s += "Warning in %s at block ending on line %s\n" % (filename, lineno) | |
|
577 | 582 | s += "Specify :okwarning: as an option in the ipython:: block to suppress this message\n" |
|
578 |
s |
|
|
579 | sys.stdout.write(s) | |
|
580 | sys.stdout.write(('-' * 76) + '\n') | |
|
581 | s=warnings.formatwarning(w.message, w.category, | |
|
582 | w.filename, w.lineno, w.line) | |
|
583 | sys.stdout.write(s) | |
|
584 | sys.stdout.write('<<<' + ('-' * 73) + '\n') | |
|
583 | s += ('-' * 76) + '\n' | |
|
584 | s += warnings.formatwarning(w.message, w.category, | |
|
585 | w.filename, w.lineno, w.line) | |
|
586 | s += '<<<' + ('-' * 73) | |
|
587 | logger.warning(s) | |
|
585 | 588 | if self.warning_is_error: |
|
586 | 589 | raise RuntimeError('Non Expected warning in `{}` line {}'.format(filename, lineno)) |
|
587 | 590 | |
@@ -1002,6 +1005,9 b' class IPythonDirective(Directive):' | |||
|
1002 | 1005 | lines = ['.. code-block:: ipython', ''] |
|
1003 | 1006 | figures = [] |
|
1004 | 1007 | |
|
1008 | # Use sphinx logger for warnings | |
|
1009 | logger = logging.getLogger(__name__) | |
|
1010 | ||
|
1005 | 1011 | for part in parts: |
|
1006 | 1012 | block = block_parser(part, rgxin, rgxout, promptin, promptout) |
|
1007 | 1013 | if len(block): |
@@ -1020,7 +1026,7 b' class IPythonDirective(Directive):' | |||
|
1020 | 1026 | if self.shell.warning_is_error: |
|
1021 | 1027 | raise RuntimeError(message) |
|
1022 | 1028 | else: |
|
1023 |
|
|
|
1029 | logger.warning(message) | |
|
1024 | 1030 | |
|
1025 | 1031 | for figure in figures: |
|
1026 | 1032 | lines.append('') |
General Comments 0
You need to be logged in to leave comments.
Login now