Skip to content

Commit

Permalink
Update IPython imports for new IPython/Jupyter separation
Browse files Browse the repository at this point in the history
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 mantidproject#16911
  • Loading branch information
martyngigg committed Aug 5, 2016
1 parent 210baec commit 744972b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Framework/PythonInterface/mantid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 15 additions & 2 deletions MantidPlot/ipython_widget/mantid_ipython_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import inspect
import threading
import types
import warnings

from PyQt4 import QtGui

Expand All @@ -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.
Expand Down

0 comments on commit 744972b

Please sign in to comment.