From 751b8b94f3d0415259678069f77d6729e75ec85c Mon Sep 17 00:00:00 2001 From: Ross Whitfield <whitfieldre@ornl.gov> Date: Wed, 14 Feb 2018 15:50:13 -0500 Subject: [PATCH] Fix workbench for IPython 6 ._update_indent() was changed not to take arguments and IPython.core.usage.quick_guide was removed. In test_execute_async_returns_failure_on_runtime_error_and_captures_expected_stack the comment was causing an IndentationError, changing it to a docstring fixes the problem. I don't think this is related to IPython but probably a python 3.6 problem. --- .../workbench/workbench/plugins/jupyterconsole.py | 6 +++++- qt/python/mantidqt/widgets/codeeditor/execution.py | 2 +- qt/python/mantidqt/widgets/codeeditor/inputsplitter.py | 5 ++++- .../mantidqt/widgets/codeeditor/test/test_execution.py | 4 ++-- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/qt/applications/workbench/workbench/plugins/jupyterconsole.py b/qt/applications/workbench/workbench/plugins/jupyterconsole.py index 7226e26b17b..4fee6d842df 100644 --- a/qt/applications/workbench/workbench/plugins/jupyterconsole.py +++ b/qt/applications/workbench/workbench/plugins/jupyterconsole.py @@ -21,7 +21,11 @@ import sys # third-party library imports from mantidqt.widgets.jupyterconsole import InProcessJupyterConsole -from IPython.core.usage import quick_guide, release as ipy_release +try: + from IPython.core.usage import quick_guide +except ImportError: # quick_guide was removed in IPython 6.0 + quick_guide = '' +from IPython.core.usage import release as ipy_release from matplotlib import __version__ as mpl_version from numpy.version import version as np_version from qtpy.QtWidgets import QVBoxLayout diff --git a/qt/python/mantidqt/widgets/codeeditor/execution.py b/qt/python/mantidqt/widgets/codeeditor/execution.py index 990c348c2f4..e36cbb8105e 100644 --- a/qt/python/mantidqt/widgets/codeeditor/execution.py +++ b/qt/python/mantidqt/widgets/codeeditor/execution.py @@ -149,7 +149,7 @@ class PythonCodeExecution(QObject): self._task = task return task - def execute(self, code_str, filename=''): + def execute(self, code_str, filename=None): """Execute the given code on the calling thread within the provided context. diff --git a/qt/python/mantidqt/widgets/codeeditor/inputsplitter.py b/qt/python/mantidqt/widgets/codeeditor/inputsplitter.py index 738a33a264c..a13256d2309 100644 --- a/qt/python/mantidqt/widgets/codeeditor/inputsplitter.py +++ b/qt/python/mantidqt/widgets/codeeditor/inputsplitter.py @@ -68,7 +68,10 @@ class InputSplitter(IPyInputSplitter): if source.endswith('\\\n'): return False - self._update_indent(lines) + try: + self._update_indent(lines) + except TypeError: # _update_indent was changed in IPython 6.0 + self._update_indent() try: self.code = self._compile(source, symbol="exec") # Invalid syntax can produce any of a number of different errors from diff --git a/qt/python/mantidqt/widgets/codeeditor/test/test_execution.py b/qt/python/mantidqt/widgets/codeeditor/test/test_execution.py index 4c4c5f5960f..b0d6a5b7865 100644 --- a/qt/python/mantidqt/widgets/codeeditor/test/test_execution.py +++ b/qt/python/mantidqt/widgets/codeeditor/test/test_execution.py @@ -111,7 +111,7 @@ class PythonCodeExecutionTest(unittest.TestCase): code = """ def foo(): def bar(): - # raises a NameError + \"""raises a NameError\""" y = _local + 1 # call inner bar() @@ -220,7 +220,7 @@ squared = sum*sum executor = PythonCodeExecution() self.assertRaises(expected_exc_type, executor.execute, code) - def _run_async_code(self, code, with_progress=False, filename=''): + def _run_async_code(self, code, with_progress=False, filename=None): executor = PythonCodeExecution() if with_progress: recv = ReceiverWithProgress() -- GitLab