##// END OF EJS Templates
Merge pull request #13030 from rhshadrach/ipython_warning...
Blazej Michalik -
r26627:6c01e9bd merge
parent child Browse files
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
@@ -557,15 +558,20 b' class EmbeddedSphinxShell(object):'
557 558 filename = self.directive.state.document.current_source
558 559 lineno = self.directive.state.document.current_line
559 560
561 # Use sphinx logger for warnings
562 logger = logging.getLogger(__name__)
563
560 564 # output any exceptions raised during execution to stdout
561 565 # unless :okexcept: has been specified.
562 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)
566 if not is_okexcept and (
567 ("Traceback" in processed_output) or ("SyntaxError" in processed_output)
568 ):
569 s = "\n>>>" + ("-" * 73) + "\n"
570 s += "Exception in %s at block ending on line %s\n" % (filename, lineno)
564 571 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')
572 s += processed_output + "\n"
573 s += "<<<" + ("-" * 73)
574 logger.warning(s)
569 575 if self.warning_is_error:
570 576 raise RuntimeError('Non Expected exception in `{}` line {}'.format(filename, lineno))
571 577
@@ -573,15 +579,15 b' class EmbeddedSphinxShell(object):'
573 579 # unless :okwarning: has been specified.
574 580 if not is_okwarning:
575 581 for w in ws:
576 s = "\nWarning in %s at block ending on line %s\n" % (filename, lineno)
582 s = "\n>>>" + ("-" * 73) + "\n"
583 s += "Warning in %s at block ending on line %s\n" % (filename, lineno)
577 584 s += "Specify :okwarning: as an option in the ipython:: block to suppress this message\n"
578 sys.stdout.write('\n\n>>>' + ('-' * 73))
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')
585 s += ("-" * 76) + "\n"
586 s += warnings.formatwarning(
587 w.message, w.category, w.filename, w.lineno, w.line
588 )
589 s += "<<<" + ("-" * 73)
590 logger.warning(s)
585 591 if self.warning_is_error:
586 592 raise RuntimeError('Non Expected warning in `{}` line {}'.format(filename, lineno))
587 593
@@ -1002,6 +1008,9 b' class IPythonDirective(Directive):'
1002 1008 lines = ['.. code-block:: ipython', '']
1003 1009 figures = []
1004 1010
1011 # Use sphinx logger for warnings
1012 logger = logging.getLogger(__name__)
1013
1005 1014 for part in parts:
1006 1015 block = block_parser(part, rgxin, rgxout, promptin, promptout)
1007 1016 if len(block):
@@ -1020,7 +1029,7 b' class IPythonDirective(Directive):'
1020 1029 if self.shell.warning_is_error:
1021 1030 raise RuntimeError(message)
1022 1031 else:
1023 warnings.warn(message)
1032 logger.warning(message)
1024 1033
1025 1034 for figure in figures:
1026 1035 lines.append('')
General Comments 0
You need to be logged in to leave comments. Login now