From 1974a2d94be6ad781c44e4f8735c81f572bc47a0 Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Mon, 6 Sep 2021 10:06:46 -0500 Subject: [PATCH 1/4] Testing: Improve test for the automatic backend --- spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py b/spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py index 91dcf88d020..77b5946ea06 100644 --- a/spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py +++ b/spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py @@ -303,14 +303,14 @@ def test_auto_backend(ipyconsole, qtbot): timeout=SHELL_TIMEOUT) with qtbot.waitSignal(shell.executed): - shell.execute("import matplotlib; matplotlib.get_backend()") + shell.execute("ip = get_ipython(); ip.kernel.eventloop") # Assert there are no errors in the console and we set the right # backend. control = ipyconsole.get_focus_widget() assert 'NOTE' not in control.toPlainText() assert 'Error' not in control.toPlainText() - assert 'Qt5Agg' in control.toPlainText() + assert 'loop_qt5' in control.toPlainText() @flaky(max_runs=3) From 3863cbf3fbd4bb66fe598cef59b4540565e725e3 Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Mon, 6 Sep 2021 11:07:10 -0500 Subject: [PATCH 2/4] git subrepo clone --branch=mpl-backend --force https://github.com/ccordoba12/spyder-kernels.git external-deps/spyder-kernels subrepo: subdir: "external-deps/spyder-kernels" merged: "8df97e568" upstream: origin: "https://github.com/ccordoba12/spyder-kernels.git" branch: "mpl-backend" commit: "8df97e568" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo" commit: "2f68596" --- external-deps/spyder-kernels/.gitrepo | 6 +++--- .../spyder-kernels/spyder_kernels/console/kernel.py | 8 ++++++-- external-deps/spyder-kernels/spyder_kernels/utils/mpl.py | 9 ++++++++- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/external-deps/spyder-kernels/.gitrepo b/external-deps/spyder-kernels/.gitrepo index a856e7a51fc..26605c6f39b 100644 --- a/external-deps/spyder-kernels/.gitrepo +++ b/external-deps/spyder-kernels/.gitrepo @@ -5,8 +5,8 @@ ; [subrepo] remote = https://github.com/spyder-ide/spyder-kernels.git - branch = 2.x - commit = d151e3b4f01a1284487b6183def17161307f8bb5 - parent = eb1cd5b7fe9ddb77a1869512c129d89c93484a46 + branch = mpl-backend + commit = 8df97e568f4ce822b5828dd62dfd8209652513bb + parent = 7ee2e237ca73c646840b549522b9282f646129a1 method = merge cmdver = 0.4.3 diff --git a/external-deps/spyder-kernels/spyder_kernels/console/kernel.py b/external-deps/spyder-kernels/spyder_kernels/console/kernel.py index bef1924821c..1494751f43e 100644 --- a/external-deps/spyder-kernels/spyder_kernels/console/kernel.py +++ b/external-deps/spyder-kernels/spyder_kernels/console/kernel.py @@ -718,6 +718,7 @@ def _set_mpl_backend(self, backend, pylab=False): """ import traceback from IPython.core.getipython import get_ipython + import matplotlib generic_error = ( "\n" + "="*73 + "\n" @@ -730,12 +731,16 @@ def _set_mpl_backend(self, backend, pylab=False): error = None try: + # This prevents Matplotlib to automatically set the backend, which + # overrides our own mechanism. + matplotlib.rcParams['backend'] = 'Agg' + + # Set the backend get_ipython().run_line_magic(magic, backend) except RuntimeError as err: # This catches errors generated by ipykernel when # trying to set a backend. See issue 5541 if "GUI eventloops" in str(err): - import matplotlib previous_backend = matplotlib.get_backend() if not backend in previous_backend.lower(): # Only inform about an error if the user selected backend @@ -748,7 +753,6 @@ def _set_mpl_backend(self, backend, pylab=False): "in use.\n\n" "Your backend will be {0}".format(previous_backend) ) - del matplotlib # This covers other RuntimeError's else: error = generic_error.format(traceback.format_exc()) diff --git a/external-deps/spyder-kernels/spyder_kernels/utils/mpl.py b/external-deps/spyder-kernels/spyder_kernels/utils/mpl.py index 26538de369f..eeec1983b41 100644 --- a/external-deps/spyder-kernels/spyder_kernels/utils/mpl.py +++ b/external-deps/spyder-kernels/spyder_kernels/utils/mpl.py @@ -18,9 +18,16 @@ } +# Inline backend +if is_module_installed('matplotlib_inline'): + inline_backend = 'module://matplotlib_inline.backend_inline' +else: + inline_backend = 'module://ipykernel.pylab.backend_inline' + + # Mapping of matlotlib backends options to Spyder MPL_BACKENDS_TO_SPYDER = { - 'module://ipykernel.pylab.backend_inline': 0, + inline_backend: 0, 'Qt5Agg': 2, 'Qt4Agg': 3, 'MacOSX': 4, From 02498d20fc2731a6f52f110c50d5b07cfc3ede22 Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Mon, 6 Sep 2021 11:14:11 -0500 Subject: [PATCH 3/4] Testing: Add a test for the Tkinter backend --- pytest.ini | 1 + .../tests/test_ipythonconsole.py | 25 ++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/pytest.ini b/pytest.ini index ac5e04a96b8..81f0852f927 100644 --- a/pytest.ini +++ b/pytest.ini @@ -29,3 +29,4 @@ markers = no_xvfb external_interpreter test_environment_interpreter + tk_backend: Test the Tkinter Matplotlib backend diff --git a/spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py b/spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py index 77b5946ea06..f02c3be0188 100644 --- a/spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py +++ b/spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py @@ -141,6 +141,11 @@ def __getattr__(self, attr): if auto_backend: CONF.set('ipython_console', 'pylab/backend', 1) + # Use the Tkinter backend if requested + tk_backend = request.node.get_closest_marker('tk_backend') + if tk_backend: + CONF.set('ipython_console', 'pylab/backend', 8) + # Start a Pylab client if requested pylab_client = request.node.get_closest_marker('pylab_client') is_pylab = True if pylab_client else False @@ -296,7 +301,7 @@ def test_get_calltips(ipyconsole, qtbot, function, signature, documentation): @flaky(max_runs=3) @pytest.mark.auto_backend def test_auto_backend(ipyconsole, qtbot): - """Test that the automatic backend is working correctly.""" + """Test that the automatic backend was set correctly.""" # Wait until the window is fully up shell = ipyconsole.get_current_shellwidget() qtbot.waitUntil(lambda: shell._prompt_html is not None, @@ -313,6 +318,24 @@ def test_auto_backend(ipyconsole, qtbot): assert 'loop_qt5' in control.toPlainText() +@flaky(max_runs=3) +@pytest.mark.tk_backend +@pytest.mark.skipif(os.name == 'nt', reason="Fails on Windows") +def test_tk_backend(ipyconsole, qtbot): + """Test that the Tkinter backend was set correctly.""" + # Wait until the window is fully up + shell = ipyconsole.get_current_shellwidget() + qtbot.waitUntil(lambda: shell._prompt_html is not None, + timeout=SHELL_TIMEOUT) + + with qtbot.waitSignal(shell.executed): + shell.execute("ip = get_ipython(); ip.kernel.eventloop") + + # Assert we set the right backend in the kernel. + control = ipyconsole.get_focus_widget() + assert 'loop_tk' in control.toPlainText() + + @flaky(max_runs=3) @pytest.mark.pylab_client def test_pylab_client(ipyconsole, qtbot): From e09e6f7c3f387c104258e701b2721bf04aefa0d9 Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Sat, 2 Oct 2021 11:51:48 -0500 Subject: [PATCH 4/4] git subrepo clone (merge) --branch=2.x --force https://github.com/spyder-ide/spyder-kernels.git external-deps/spyder-kernels subrepo: subdir: "external-deps/spyder-kernels" merged: "f7888cff5" upstream: origin: "https://github.com/spyder-ide/spyder-kernels.git" branch: "2.x" commit: "f7888cff5" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo" commit: "2f68596" [ci skip] --- external-deps/spyder-kernels/.gitrepo | 6 +++--- external-deps/spyder-kernels/CHANGELOG.md | 14 +++++++++++++- .../spyder-kernels/requirements/tests.txt | 2 ++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/external-deps/spyder-kernels/.gitrepo b/external-deps/spyder-kernels/.gitrepo index 26605c6f39b..7de9b43461a 100644 --- a/external-deps/spyder-kernels/.gitrepo +++ b/external-deps/spyder-kernels/.gitrepo @@ -5,8 +5,8 @@ ; [subrepo] remote = https://github.com/spyder-ide/spyder-kernels.git - branch = mpl-backend - commit = 8df97e568f4ce822b5828dd62dfd8209652513bb - parent = 7ee2e237ca73c646840b549522b9282f646129a1 + branch = 2.x + commit = f7888cff5f6280e48076fb8ff1948d335464b6f8 + parent = 02498d20fc2731a6f52f110c50d5b07cfc3ede22 method = merge cmdver = 0.4.3 diff --git a/external-deps/spyder-kernels/CHANGELOG.md b/external-deps/spyder-kernels/CHANGELOG.md index d1b83d7f8dc..dd55113dc7a 100644 --- a/external-deps/spyder-kernels/CHANGELOG.md +++ b/external-deps/spyder-kernels/CHANGELOG.md @@ -1,8 +1,20 @@ # History of changes -## Version 2.1.1 (2021-09-01) +## Version 2.1.2 (2021-09-28) + +### Pull Requests Merged + +* [PR 323](https://github.com/spyder-ide/spyder-kernels/pull/323) - PR: Add `ipython_genutils` dependency for testing, by [@ccordoba12](https://github.com/ccordoba12) +* [PR 322](https://github.com/spyder-ide/spyder-kernels/pull/322) - PR: Prevent other libraries to change the breakpoint builtin, by [@ccordoba12](https://github.com/ccordoba12) + +In this release 2 pull requests were closed. +---- + + +## Version 2.1.1 (2021-09-01) + ### Pull Requests Merged * [PR 318](https://github.com/spyder-ide/spyder-kernels/pull/318) - PR: Avoid runfile to be shadowed by other packages, by [@ccordoba12](https://github.com/ccordoba12) diff --git a/external-deps/spyder-kernels/requirements/tests.txt b/external-deps/spyder-kernels/requirements/tests.txt index 68994b5f371..5b737c8dd0f 100644 --- a/external-deps/spyder-kernels/requirements/tests.txt +++ b/external-deps/spyder-kernels/requirements/tests.txt @@ -11,3 +11,5 @@ pytest-cov scipy xarray pillow +# Remove when Anaconda updates to a newer ipykernel +ipython_genutils