From 744972b7b4bec2e2319ebc1b6f798556bac7ccd0 Mon Sep 17 00:00:00 2001 From: Martyn Gigg Date: Fri, 5 Aug 2016 17:51:34 +0100 Subject: [PATCH] Update IPython imports for new IPython/Jupyter separation Many warnings are suppressed from IPython/Jupyter as we can do nothing about them. A single warning remains regarding insecure messaging that appears to be a bug in IPython. Refs #16911 --- Framework/PythonInterface/mantid/__init__.py | 3 ++- .../ipython_widget/mantid_ipython_widget.py | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Framework/PythonInterface/mantid/__init__.py b/Framework/PythonInterface/mantid/__init__.py index 1e756bc460ef..b76a24c27754 100644 --- a/Framework/PythonInterface/mantid/__init__.py +++ b/Framework/PythonInterface/mantid/__init__.py @@ -48,7 +48,8 @@ def apiVersion(): ############################################################################### import warnings as _warnings # Default we see everything -_warnings.filterwarnings("default",category=DeprecationWarning) +_warnings.filterwarnings("default",category=DeprecationWarning, + module="mantid.*") # We can't do anything about numpy.oldnumeric being deprecated but # still used in other libraries, e.g scipy, so just ignore those _warnings.filterwarnings("ignore",category=DeprecationWarning, diff --git a/MantidPlot/ipython_widget/mantid_ipython_widget.py b/MantidPlot/ipython_widget/mantid_ipython_widget.py index 0ac7c5557306..344828b31860 100644 --- a/MantidPlot/ipython_widget/mantid_ipython_widget.py +++ b/MantidPlot/ipython_widget/mantid_ipython_widget.py @@ -4,6 +4,7 @@ import inspect import threading import types +import warnings from PyQt4 import QtGui @@ -14,8 +15,20 @@ # Monkeypatch! RegexLexer.get_tokens_unprocessed_unpatched = RegexLexer.get_tokens_unprocessed -from IPython.qt.console.rich_ipython_widget import RichIPythonWidget -from IPython.qt.inprocess import QtInProcessKernelManager +# Ignore Jupyter/IPython deprecation warnings that we can't do anything about +warnings.filterwarnings('ignore', category=DeprecationWarning, module='IPython.*') +warnings.filterwarnings('ignore', category=DeprecationWarning, module='ipykernel.*') +warnings.filterwarnings('ignore', category=DeprecationWarning, module='jupyter_client.*') +warnings.filterwarnings('ignore', category=DeprecationWarning, module='qtconsole.*') +del warnings + +try: + # Later versions of Qtconsole are part of Jupyter + from qtconsole.rich_jupyter_widget import RichJupyterWidget as RichIPythonWidget + from qtconsole.inprocess import QtInProcessKernelManager +except ImportError: + from IPython.qt.console.rich_ipython_widget import RichIPythonWidget + from IPython.qt.inprocess import QtInProcessKernelManager def our_run_code(self, code_obj, result=None): """ Method with which we replace the run_code method of IPython's InteractiveShell class.