From d9f566127daf914b905f8f749bc5fb7898c869b7 Mon Sep 17 00:00:00 2001 From: Quentin Peter Date: Fri, 14 Jan 2022 08:53:07 +0100 Subject: [PATCH 1/7] add test unsaved file debugging fix test --- spyder/app/tests/test_mainwindow.py | 40 +++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/spyder/app/tests/test_mainwindow.py b/spyder/app/tests/test_mainwindow.py index 300598fa4d2..5d03e666348 100644 --- a/spyder/app/tests/test_mainwindow.py +++ b/spyder/app/tests/test_mainwindow.py @@ -4472,5 +4472,45 @@ def test_rename_files_in_editor_after_folder_rename(main_window, mocker, assert codeeditor.filename == osp.join(str(tmpdir), new_path, fname) +@pytest.mark.slow +def test_debug_unsaved_function(main_window, qtbot): + """ + Test that a breakpoint in an unsaved file is reached. + """ + # Wait until the window is fully up + shell = main_window.ipyconsole.get_current_shellwidget() + qtbot.waitUntil(lambda: shell._prompt_html is not None, + timeout=SHELL_TIMEOUT) + + # Main variables + control = shell._control + run_action = main_window.run_toolbar_actions[0] + run_button = main_window.run_toolbar.widgetForAction(run_action) + + # Clear all breakpoints + main_window.editor.clear_all_breakpoints() + + # create new file + main_window.editor.new() + code_editor = main_window.editor.get_focus_widget() + code_editor.set_text('def foo():\n print(1)') + + # Set breakpoint + code_editor.debugger.toogle_breakpoint(line_number=2) + + # run file + with qtbot.waitSignal(shell.executed): + qtbot.mouseClick(run_button, Qt.LeftButton) + + # debug foo + with qtbot.waitSignal(shell.executed): + shell.execute('%debug foo()') + + with qtbot.waitSignal(shell.executed): + shell.execute('continue') + + assert "1---> 2 print(1)" in control.toPlainText() + + if __name__ == "__main__": pytest.main() From 7a1fde0927d4ac3098880f4680a6a635b4b1c194 Mon Sep 17 00:00:00 2001 From: Quentin Peter Date: Fri, 14 Jan 2022 08:50:26 +0100 Subject: [PATCH 2/7] git subrepo clone --branch=unsaved_linecache --force https://github.com/impact27/spyder-kernels.git external-deps/spyder-kernels subrepo: subdir: "external-deps/spyder-kernels" merged: "84034ed5b" upstream: origin: "https://github.com/impact27/spyder-kernels.git" branch: "unsaved_linecache" commit: "84034ed5b" git-subrepo: version: "0.4.1" origin: "https://github.com/ingydotnet/git-subrepo" commit: "a04d8c2" --- .../.github/workflows/windows-tests.yml | 2 +- external-deps/spyder-kernels/.gitrepo | 8 ++--- external-deps/spyder-kernels/CHANGELOG.md | 36 +++++++++++++++++++ .../spyder_kernels/comms/frontendcomm.py | 31 +++++++++++----- .../spyder_kernels/console/kernel.py | 9 +++++ .../customize/namespace_manager.py | 5 +-- 6 files changed, 75 insertions(+), 16 deletions(-) diff --git a/external-deps/spyder-kernels/.github/workflows/windows-tests.yml b/external-deps/spyder-kernels/.github/workflows/windows-tests.yml index 83912073c60..f782e18e31a 100644 --- a/external-deps/spyder-kernels/.github/workflows/windows-tests.yml +++ b/external-deps/spyder-kernels/.github/workflows/windows-tests.yml @@ -22,7 +22,7 @@ jobs: fail-fast: false matrix: PYTHON_VERSION: ['3.7', '3.8', '3.9'] - timeout-minutes: 10 + timeout-minutes: 25 steps: - name: Checkout branch uses: actions/checkout@v1 diff --git a/external-deps/spyder-kernels/.gitrepo b/external-deps/spyder-kernels/.gitrepo index 35be8a0a9e0..0e4bac555d7 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 = 8f9fde2635ddd0fa34744f566966f5a4dee8f108 - parent = e29db93e2a67ca98cd9e7da4b356bb685bf53a29 + branch = unsaved_linecache + commit = 84034ed5bade368de29653e1fb1765f3be9242fc + parent = a5033a768b8b8c4ad08e7eada5fde2ae53715250 method = merge - cmdver = 0.4.3 + cmdver = 0.4.1 diff --git a/external-deps/spyder-kernels/CHANGELOG.md b/external-deps/spyder-kernels/CHANGELOG.md index 52d9595b7ee..88a39e6449b 100644 --- a/external-deps/spyder-kernels/CHANGELOG.md +++ b/external-deps/spyder-kernels/CHANGELOG.md @@ -1,5 +1,41 @@ # History of changes +## Version 2.2.1 (2022-01-13) + +### Issues Closed + +* [Issue 365](https://github.com/spyder-ide/spyder-kernels/issues/365) - `IOStream.flush timed out` message shown after every evaluation ([PR 367](https://github.com/spyder-ide/spyder-kernels/pull/367) by [@ccordoba12](https://github.com/ccordoba12)) +* [Issue 347](https://github.com/spyder-ide/spyder-kernels/issues/347) - Issues handling Matplotlib backend settings ([PR 368](https://github.com/spyder-ide/spyder-kernels/pull/368) by [@ccordoba12](https://github.com/ccordoba12)) +* [Issue 345](https://github.com/spyder-ide/spyder-kernels/issues/345) - Namespace issues ([PR 346](https://github.com/spyder-ide/spyder-kernels/pull/346) by [@impact27](https://github.com/impact27)) +* [Issue 343](https://github.com/spyder-ide/spyder-kernels/issues/343) - Shapely 1.8 and get_namespace_view spyder call raising deprecation warning ([PR 350](https://github.com/spyder-ide/spyder-kernels/pull/350) by [@ccordoba12](https://github.com/ccordoba12)) + +In this release 4 issues were closed. + +### Pull Requests Merged + +* [PR 368](https://github.com/spyder-ide/spyder-kernels/pull/368) - PR: Improve error message when setting a Matplotlib backend whose module is not present, by [@ccordoba12](https://github.com/ccordoba12) ([347](https://github.com/spyder-ide/spyder-kernels/issues/347)) +* [PR 367](https://github.com/spyder-ide/spyder-kernels/pull/367) - PR: Filter another benign message coming from comm handlers, by [@ccordoba12](https://github.com/ccordoba12) ([365](https://github.com/spyder-ide/spyder-kernels/issues/365)) +* [PR 364](https://github.com/spyder-ide/spyder-kernels/pull/364) - PR: Catch error when validating if an object is defined in the namespace, by [@ccordoba12](https://github.com/ccordoba12) +* [PR 363](https://github.com/spyder-ide/spyder-kernels/pull/363) - PR: Fix error when running multiprocessing code that contains classes, by [@impact27](https://github.com/impact27) +* [PR 362](https://github.com/spyder-ide/spyder-kernels/pull/362) - PR: Catch KeyError when closing comm, by [@ccordoba12](https://github.com/ccordoba12) +* [PR 361](https://github.com/spyder-ide/spyder-kernels/pull/361) - PR: Increase minimal required version of pyzmq for Python 3, by [@ccordoba12](https://github.com/ccordoba12) +* [PR 360](https://github.com/spyder-ide/spyder-kernels/pull/360) - PR: Increase minimal required version of ipykernel to 6.6.1, by [@ccordoba12](https://github.com/ccordoba12) +* [PR 357](https://github.com/spyder-ide/spyder-kernels/pull/357) - PR: Require jupyter-client 7.1.0 to fix issues on Windows, by [@ccordoba12](https://github.com/ccordoba12) +* [PR 356](https://github.com/spyder-ide/spyder-kernels/pull/356) - PR: Increase minimal required version of jupyter-client to 7.0+ for Python 3, by [@ccordoba12](https://github.com/ccordoba12) +* [PR 354](https://github.com/spyder-ide/spyder-kernels/pull/354) - PR: Constraint IPython version to avoid issues when its next major version is released, by [@ccordoba12](https://github.com/ccordoba12) +* [PR 353](https://github.com/spyder-ide/spyder-kernels/pull/353) - PR: Implement a less hacky solution to fix namespace issues, by [@impact27](https://github.com/impact27) +* [PR 351](https://github.com/spyder-ide/spyder-kernels/pull/351) - PR: More namespace fixes, by [@impact27](https://github.com/impact27) +* [PR 350](https://github.com/spyder-ide/spyder-kernels/pull/350) - PR: Don't print DeprecationWarning's that come from comm handlers, by [@ccordoba12](https://github.com/ccordoba12) ([343](https://github.com/spyder-ide/spyder-kernels/issues/343)) +* [PR 349](https://github.com/spyder-ide/spyder-kernels/pull/349) - PR: Update Quansight logo in Readme, by [@ccordoba12](https://github.com/ccordoba12) +* [PR 346](https://github.com/spyder-ide/spyder-kernels/pull/346) - PR: Fix some namespace issues, by [@impact27](https://github.com/impact27) ([345](https://github.com/spyder-ide/spyder-kernels/issues/345)) +* [PR 338](https://github.com/spyder-ide/spyder-kernels/pull/338) - PR: Fix misplaced section in changelog, by [@ccordoba12](https://github.com/ccordoba12) + +In this release 16 pull requests were closed. + + +---- + + ## Version 2.2.0 (2021-11-22) ### New features diff --git a/external-deps/spyder-kernels/spyder_kernels/comms/frontendcomm.py b/external-deps/spyder-kernels/spyder_kernels/comms/frontendcomm.py index a765a27f893..cc8cba3357b 100644 --- a/external-deps/spyder-kernels/spyder_kernels/comms/frontendcomm.py +++ b/external-deps/spyder-kernels/spyder_kernels/comms/frontendcomm.py @@ -271,7 +271,7 @@ def _remote_callback(self, call_name, call_args, call_kwargs): sys.stderr.write = saved_stderr_write -class WriteWrapper(): +class WriteWrapper(object): """Wrapper to warn user when text is printed.""" def __init__(self, write, name): @@ -279,16 +279,29 @@ def __init__(self, write, name): self._name = name self._warning_shown = False + def is_benign_message(self, message): + """Determine if a message is benign in order to filter it.""" + benign_messages = [ + # Fixes spyder-ide/spyder#14928 + # Fixes spyder-ide/spyder-kernels#343 + 'DeprecationWarning', + # Fixes spyder-ide/spyder-kernels#365 + 'IOStream.flush timed out' + ] + + return any([msg in message for msg in benign_messages]) + def __call__(self, string): """Print warning once.""" - # Don't print DeprecationWarning's because they unnecessarily pollute - # the console. - # Fixes spyder-ide/spyder#14928 - # Fixes spyder-ide/spyder-kernels#343 - if 'DeprecationWarning' not in string: + if not self.is_benign_message(string): if not self._warning_shown: self._warning_shown = True - self._write( - "\nOutput from spyder call " - + repr(self._name) + ":\n") + + # Don't print handler name for `show_mpl_backend_errors` + # because we have a specific message for it. + if repr(self._name) != "'show_mpl_backend_errors'": + self._write( + "\nOutput from spyder call " + repr(self._name) + ":\n" + ) + return self._write(string) diff --git a/external-deps/spyder-kernels/spyder_kernels/console/kernel.py b/external-deps/spyder-kernels/spyder_kernels/console/kernel.py index ae19295912b..751c26c2365 100644 --- a/external-deps/spyder-kernels/spyder_kernels/console/kernel.py +++ b/external-deps/spyder-kernels/spyder_kernels/console/kernel.py @@ -740,6 +740,15 @@ def _set_mpl_backend(self, backend, pylab=False): # This covers other RuntimeError's else: error = generic_error.format(traceback.format_exc()) + except ImportError as err: + additional_info = ( + "This is most likely caused by missing packages in the Python " + "environment\n" + "or installation whose interpreter is located at:\n\n" + " {0}" + ).format(sys.executable) + + error = generic_error.format(err) + '\n\n' + additional_info except Exception: error = generic_error.format(traceback.format_exc()) diff --git a/external-deps/spyder-kernels/spyder_kernels/customize/namespace_manager.py b/external-deps/spyder-kernels/spyder_kernels/customize/namespace_manager.py index 1f293882edb..359db302aba 100755 --- a/external-deps/spyder-kernels/spyder_kernels/customize/namespace_manager.py +++ b/external-deps/spyder-kernels/spyder_kernels/customize/namespace_manager.py @@ -4,8 +4,9 @@ # Licensed under the terms of the MIT License # (see spyder_kernels/__init__.py for details) -import sys import linecache +import os.path +import sys from IPython.core.getipython import get_ipython @@ -103,5 +104,5 @@ def __exit__(self, exc_type, exc_val, exc_tb): sys.modules['__main__'] = self._previous_main elif '__main__' in sys.modules and self._reset_main: del sys.modules['__main__'] - if self.filename in linecache.cache: + if self.filename in linecache.cache and os.path.exists(self.filename): linecache.cache.pop(self.filename) From 07fcf0cce2ff5fada7a4836773c013e0795f5e9f Mon Sep 17 00:00:00 2001 From: Quentin Peter Date: Fri, 14 Jan 2022 11:31:37 +0100 Subject: [PATCH 3/7] git subrepo clone --branch=unsaved_linecache --force https://github.com/impact27/spyder-kernels.git external-deps/spyder-kernels subrepo: subdir: "external-deps/spyder-kernels" merged: "ef5c68f7d" upstream: origin: "https://github.com/impact27/spyder-kernels.git" branch: "unsaved_linecache" commit: "ef5c68f7d" git-subrepo: version: "0.4.1" origin: "https://github.com/ingydotnet/git-subrepo" commit: "a04d8c2" --- external-deps/spyder-kernels/.gitrepo | 4 ++-- .../spyder_kernels/customize/spydercustomize.py | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/external-deps/spyder-kernels/.gitrepo b/external-deps/spyder-kernels/.gitrepo index 0e4bac555d7..0b7a6104636 100644 --- a/external-deps/spyder-kernels/.gitrepo +++ b/external-deps/spyder-kernels/.gitrepo @@ -6,7 +6,7 @@ [subrepo] remote = https://github.com/spyder-ide/spyder-kernels.git branch = unsaved_linecache - commit = 84034ed5bade368de29653e1fb1765f3be9242fc - parent = a5033a768b8b8c4ad08e7eada5fde2ae53715250 + commit = ef5c68f7dc052e5e40eb05e53e04ae484eb606e2 + parent = 7a1fde0927d4ac3098880f4680a6a635b4b1c194 method = merge cmdver = 0.4.1 diff --git a/external-deps/spyder-kernels/spyder_kernels/customize/spydercustomize.py b/external-deps/spyder-kernels/spyder_kernels/customize/spydercustomize.py index b9781a4fdb9..bdcb4fe59ab 100644 --- a/external-deps/spyder-kernels/spyder_kernels/customize/spydercustomize.py +++ b/external-deps/spyder-kernels/spyder_kernels/customize/spydercustomize.py @@ -543,6 +543,10 @@ def runfile(filename=None, args=None, wdir=None, namespace=None, _print("Could not get code from editor.\n") return + # Normalise the filename + filename = os.path.abspath(filename) + filename = os.path.normcase(filename) + with NamespaceManager(filename, namespace, current_namespace, file_code=file_code) as (ns_globals, ns_locals): sys.argv = [filename] @@ -676,6 +680,11 @@ def runcell(cellname, filename=None, post_mortem=False): file_code = get_file_code(filename, save_all=False) except Exception: file_code = None + + # Normalise the filename + filename = os.path.abspath(filename) + filename = os.path.normcase(filename) + with NamespaceManager(filename, current_namespace=True, file_code=file_code) as (ns_globals, ns_locals): exec_code(cell_code, filename, ns_globals, ns_locals, From c880b11ca314c1d19b6c95c61591949667f6c402 Mon Sep 17 00:00:00 2001 From: Quentin Peter Date: Fri, 14 Jan 2022 13:36:36 +0100 Subject: [PATCH 4/7] skip focus --- spyder/app/tests/test_mainwindow.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spyder/app/tests/test_mainwindow.py b/spyder/app/tests/test_mainwindow.py index 5d03e666348..d81ea9b10c3 100644 --- a/spyder/app/tests/test_mainwindow.py +++ b/spyder/app/tests/test_mainwindow.py @@ -4314,6 +4314,9 @@ def crash_func(): @pytest.mark.slow @flaky(max_runs=3) @pytest.mark.parametrize("focus_to_editor", [True, False]) +@pytest.mark.skipif( + os.name == 'nt', + reason="Fails on Windows") def test_focus_to_editor(main_window, qtbot, tmpdir, focus_to_editor): """Test that the focus_to_editor option works as expected.""" # Write code with cells to a file From 6fd5175d9602ac4905b876930a241cbb9306127c Mon Sep 17 00:00:00 2001 From: Quentin Peter Date: Sat, 22 Jan 2022 00:39:33 +0100 Subject: [PATCH 5/7] Apply suggestions from code review Co-authored-by: Carlos Cordoba --- spyder/app/tests/test_mainwindow.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/spyder/app/tests/test_mainwindow.py b/spyder/app/tests/test_mainwindow.py index d81ea9b10c3..92b9c50820e 100644 --- a/spyder/app/tests/test_mainwindow.py +++ b/spyder/app/tests/test_mainwindow.py @@ -4314,9 +4314,7 @@ def crash_func(): @pytest.mark.slow @flaky(max_runs=3) @pytest.mark.parametrize("focus_to_editor", [True, False]) -@pytest.mark.skipif( - os.name == 'nt', - reason="Fails on Windows") +@pytest.mark.skipif(os.name == 'nt', reason="Fails on Windows") def test_focus_to_editor(main_window, qtbot, tmpdir, focus_to_editor): """Test that the focus_to_editor option works as expected.""" # Write code with cells to a file @@ -4481,9 +4479,6 @@ def test_debug_unsaved_function(main_window, qtbot): Test that a breakpoint in an unsaved file is reached. """ # Wait until the window is fully up - shell = main_window.ipyconsole.get_current_shellwidget() - qtbot.waitUntil(lambda: shell._prompt_html is not None, - timeout=SHELL_TIMEOUT) # Main variables control = shell._control From c9137ccd501fc73c9c268dd862e293bc095f08dd Mon Sep 17 00:00:00 2001 From: Quentin Peter Date: Mon, 24 Jan 2022 14:42:09 +0100 Subject: [PATCH 6/7] fix test --- spyder/app/tests/test_mainwindow.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spyder/app/tests/test_mainwindow.py b/spyder/app/tests/test_mainwindow.py index bcdc91d46fe..b079a7ed762 100644 --- a/spyder/app/tests/test_mainwindow.py +++ b/spyder/app/tests/test_mainwindow.py @@ -4602,9 +4602,8 @@ def test_debug_unsaved_function(main_window, qtbot): """ Test that a breakpoint in an unsaved file is reached. """ - # Wait until the window is fully up - # Main variables + shell = main_window.ipyconsole.get_current_shellwidget() control = shell._control run_action = main_window.run_toolbar_actions[0] run_button = main_window.run_toolbar.widgetForAction(run_action) From dafc2ab7614cac5fca234727386725c69886dbf2 Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Tue, 25 Jan 2022 09:58:59 -0500 Subject: [PATCH 7/7] 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: "52f9b9c09" upstream: origin: "https://github.com/spyder-ide/spyder-kernels.git" branch: "2.x" commit: "52f9b9c09" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo" commit: "2f68596" [ci skip] --- external-deps/spyder-kernels/.gitrepo | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/external-deps/spyder-kernels/.gitrepo b/external-deps/spyder-kernels/.gitrepo index 0b7a6104636..4471e595570 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 = unsaved_linecache - commit = ef5c68f7dc052e5e40eb05e53e04ae484eb606e2 - parent = 7a1fde0927d4ac3098880f4680a6a635b4b1c194 + branch = 2.x + commit = 52f9b9c09a4c07f1b9ab00ada87a0d741341db64 + parent = 97e14d2e8876460f7fdf1306fbc852274edb2ea4 method = merge - cmdver = 0.4.1 + cmdver = 0.4.3