From 0efc1453d3ccc4bafae83df65b3d614f7773cb42 Mon Sep 17 00:00:00 2001 From: dalthviz <16781833+dalthviz@users.noreply.github.com> Date: Tue, 12 Nov 2024 16:52:12 -0500 Subject: [PATCH 01/19] IPython Console: Initial traceback setup to use selected syntax style --- .../plugins/ipythonconsole/widgets/shell.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/spyder/plugins/ipythonconsole/widgets/shell.py b/spyder/plugins/ipythonconsole/widgets/shell.py index 2a8ee8d7475..84994c3b951 100644 --- a/spyder/plugins/ipythonconsole/widgets/shell.py +++ b/spyder/plugins/ipythonconsole/widgets/shell.py @@ -187,6 +187,9 @@ def __init__( self.is_kernel_configured = False self._init_kernel_setup = False self._is_banner_shown = False + # Set bright colors instead of bold formating for better traceback + # readability + self._ansi_processor.bold_text_enabled = False if handlers is None: handlers = {} @@ -449,6 +452,8 @@ def send_spyder_kernel_configuration(self): # Enable autoreload_magic self.set_kernel_configuration("autoreload_magic", True) + self.silent_execute("%xmode verbose") + self.call_kernel( interrupt=self.is_debugging(), callback=self.kernel_configure_callback @@ -1436,6 +1441,21 @@ def _syntax_style_changed(self, changed=None): if self.syntax_style: self._highlighter._style = create_style_class(self.syntax_style) self._highlighter._clear_caches() + self.silent_execute( +f""" +import IPython.core.ultratb +from IPython.core.ultratb import VerboseTB + +from spyder.plugins.ipythonconsole.utils.style import create_style_class + +IPython.core.ultratb.get_style_by_name = create_style_class + +if getattr(VerboseTB, 'tb_highlight_style', None) is not None: + VerboseTB.tb_highlight_style = '{self.syntax_style}' +elif getattr(VerboseTB, '_tb_highlight_style', None) is not None: + VerboseTB._tb_highlight_style = '{self.syntax_style}' +""" + ) else: self._highlighter.set_style_sheet(self.style_sheet) From 44a08d3c42bab44889fb3499cd81d802f3c7f801 Mon Sep 17 00:00:00 2001 From: dalthviz <16781833+dalthviz@users.noreply.github.com> Date: Thu, 14 Nov 2024 19:01:05 -0500 Subject: [PATCH 02/19] IPython Console: Enable going to file from xmode plain and context formats file paths --- spyder/app/tests/test_mainwindow.py | 6 +++--- spyder/plugins/ipythonconsole/widgets/shell.py | 2 +- spyder/utils/misc.py | 15 ++++++++++----- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/spyder/app/tests/test_mainwindow.py b/spyder/app/tests/test_mainwindow.py index 93e360d9463..412206bb569 100644 --- a/spyder/app/tests/test_mainwindow.py +++ b/spyder/app/tests/test_mainwindow.py @@ -6461,9 +6461,9 @@ def test_PYTHONPATH_in_consoles(main_window, qtbot, tmp_path, assert str(user_dir) not in sys_path -@flaky(max_runs=10) +# @flaky(max_runs=10) @pytest.mark.skipif(sys.platform == 'darwin', reason="Fails on Mac") -@pytest.mark.order(before='test_shell_execution') +# @pytest.mark.order(before='test_shell_execution') def test_clickable_ipython_tracebacks(main_window, qtbot, tmp_path): """ Test that file names in IPython console tracebacks are clickable. @@ -6502,7 +6502,7 @@ def test_clickable_ipython_tracebacks(main_window, qtbot, tmp_path): control.setFocus() find_widget = main_window.ipyconsole.get_widget().find_widget find_widget.show() - find_widget.search_text.lineEdit().setText(' File') + find_widget.search_text.lineEdit().setText('File') find_widget.find_previous() # Position mouse on top of that line diff --git a/spyder/plugins/ipythonconsole/widgets/shell.py b/spyder/plugins/ipythonconsole/widgets/shell.py index 84994c3b951..a77e4e8384d 100644 --- a/spyder/plugins/ipythonconsole/widgets/shell.py +++ b/spyder/plugins/ipythonconsole/widgets/shell.py @@ -452,7 +452,7 @@ def send_spyder_kernel_configuration(self): # Enable autoreload_magic self.set_kernel_configuration("autoreload_magic", True) - self.silent_execute("%xmode verbose") + self.silent_execute("%xmode context") self.call_kernel( interrupt=self.is_debugging(), diff --git a/spyder/utils/misc.py b/spyder/utils/misc.py index 7d8ee7126c9..50d5b0bbbd8 100644 --- a/spyder/utils/misc.py +++ b/spyder/utils/misc.py @@ -154,16 +154,21 @@ def remove_backslashes(path): def get_error_match(text): """Check if text contains a Python error.""" - # For regular Python tracebacks and IPython 7 or less. + # For regular Python tracebacks and IPython 7 or less (xmode plain). match_python = re.match(r' File "(.*)", line (\d*)', text) if match_python is not None: return match_python - # For IPython 8+ tracebacks. + # For IPython 8+ tracebacks (xmode plain). # Fixes spyder-ide/spyder#20407 - ipython8_match = re.match(r' File (.*):(\d*)', text) - if ipython8_match is not None: - return ipython8_match + ipython8_plain_match = re.match(r' File (.*):(\d*)', text) + if ipython8_plain_match is not None: + return ipython8_plain_match + + # For IPython 8+ tracebacks (xmode context). + ipython8_context_match = re.match(r'File (.*):(\d*)', text) + if ipython8_context_match is not None: + return ipython8_context_match return False From 79dcad4c1c910dea5e75e23f7a30a7d585db55ba Mon Sep 17 00:00:00 2001 From: dalthviz <16781833+dalthviz@users.noreply.github.com> Date: Fri, 15 Nov 2024 23:19:18 -0500 Subject: [PATCH 03/19] IPython Console: Use kernel configuration handler for traceback highlight style --- spyder/app/tests/test_mainwindow.py | 4 ++-- spyder/plugins/ipythonconsole/widgets/shell.py | 18 ++---------------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/spyder/app/tests/test_mainwindow.py b/spyder/app/tests/test_mainwindow.py index 412206bb569..dd029ae13f3 100644 --- a/spyder/app/tests/test_mainwindow.py +++ b/spyder/app/tests/test_mainwindow.py @@ -6461,9 +6461,9 @@ def test_PYTHONPATH_in_consoles(main_window, qtbot, tmp_path, assert str(user_dir) not in sys_path -# @flaky(max_runs=10) +@flaky(max_runs=10) @pytest.mark.skipif(sys.platform == 'darwin', reason="Fails on Mac") -# @pytest.mark.order(before='test_shell_execution') +@pytest.mark.order(before='test_shell_execution') def test_clickable_ipython_tracebacks(main_window, qtbot, tmp_path): """ Test that file names in IPython console tracebacks are clickable. diff --git a/spyder/plugins/ipythonconsole/widgets/shell.py b/spyder/plugins/ipythonconsole/widgets/shell.py index a77e4e8384d..19ee5505995 100644 --- a/spyder/plugins/ipythonconsole/widgets/shell.py +++ b/spyder/plugins/ipythonconsole/widgets/shell.py @@ -452,8 +452,6 @@ def send_spyder_kernel_configuration(self): # Enable autoreload_magic self.set_kernel_configuration("autoreload_magic", True) - self.silent_execute("%xmode context") - self.call_kernel( interrupt=self.is_debugging(), callback=self.kernel_configure_callback @@ -1441,20 +1439,8 @@ def _syntax_style_changed(self, changed=None): if self.syntax_style: self._highlighter._style = create_style_class(self.syntax_style) self._highlighter._clear_caches() - self.silent_execute( -f""" -import IPython.core.ultratb -from IPython.core.ultratb import VerboseTB - -from spyder.plugins.ipythonconsole.utils.style import create_style_class - -IPython.core.ultratb.get_style_by_name = create_style_class - -if getattr(VerboseTB, 'tb_highlight_style', None) is not None: - VerboseTB.tb_highlight_style = '{self.syntax_style}' -elif getattr(VerboseTB, '_tb_highlight_style', None) is not None: - VerboseTB._tb_highlight_style = '{self.syntax_style}' -""" + self.set_kernel_configuration( + "traceback_highlight_style", self.syntax_style ) else: self._highlighter.set_style_sheet(self.style_sheet) From 1c0bec48cc77d54c330f66a22f09a0b5d172c27a Mon Sep 17 00:00:00 2001 From: dalthviz <16781833+dalthviz@users.noreply.github.com> Date: Fri, 15 Nov 2024 23:22:15 -0500 Subject: [PATCH 04/19] git subrepo pull --remote=https://github.com/dalthviz/spyder-kernels.git --branch=spyder_22965 --update --force external-deps/spyder-kernels subrepo: subdir: "external-deps/spyder-kernels" merged: "75ebcac30" upstream: origin: "https://github.com/dalthviz/spyder-kernels.git" branch: "spyder_22965" commit: "75ebcac30" git-subrepo: version: "0.4.3" origin: "???" commit: "???" --- external-deps/spyder-kernels/.gitrepo | 10 ++++----- .../spyder_kernels/console/kernel.py | 21 +++++++++++++++++++ .../spyder_kernels/console/start.py | 3 --- .../console/tests/test_console_kernel.py | 10 +++++++-- 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/external-deps/spyder-kernels/.gitrepo b/external-deps/spyder-kernels/.gitrepo index 67bef785e7c..6130c65943f 100644 --- a/external-deps/spyder-kernels/.gitrepo +++ b/external-deps/spyder-kernels/.gitrepo @@ -4,9 +4,9 @@ ; git-subrepo command. See https://github.com/ingydotnet/git-subrepo#readme ; [subrepo] - remote = https://github.com/spyder-ide/spyder-kernels.git - branch = master - commit = f9fc2f62179a98cf582b44306a9f9225506ec532 - parent = 3d037175c3ae4bb20f1366a6e5446ae064ed6306 + remote = https://github.com/dalthviz/spyder-kernels.git + branch = spyder_22965 + commit = 75ebcac30e35d96658c59b70ee9c5f6b0cad8f98 + parent = 79dcad4c1c910dea5e75e23f7a30a7d585db55ba method = merge - cmdver = 0.4.9 + 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 ad16c08475a..e792bba8dfe 100644 --- a/external-deps/spyder-kernels/spyder_kernels/console/kernel.py +++ b/external-deps/spyder-kernels/spyder_kernels/console/kernel.py @@ -639,6 +639,8 @@ def set_configuration(self, conf): ret["special_kernel_error"] = value elif key == "color scheme": self.set_color_scheme(value) + elif key == "traceback_highlight_style": + self.set_traceback_syntax_highlighting(value) elif key == "jedi_completer": self.set_jedi_completer(value) elif key == "greedy_completer": @@ -665,6 +667,25 @@ def set_color_scheme(self, color_scheme): self.shell.run_line_magic("colors", "lightbg") self.set_sympy_forecolor(background_color='light') + def set_traceback_syntax_highlighting(self, syntax_style): + """Set the traceback syntax highlighting.""" + try: + import IPython.core.ultratb + from IPython.core.ultratb import VerboseTB + + from spyder.plugins.ipythonconsole.utils.style import create_style_class + + IPython.core.ultratb.get_style_by_name = create_style_class + + if getattr(VerboseTB, 'tb_highlight_style', None) is not None: + VerboseTB.tb_highlight_style = syntax_style + elif getattr(VerboseTB, '_tb_highlight_style', None) is not None: + VerboseTB._tb_highlight_style = syntax_style + except Exception: + # Only usable if the kernel has access to Spyder syntax style function logic + # i.e spyder-kernels and Spyder are installed in the same environment + pass + def get_cwd(self): """Get current working directory.""" try: diff --git a/external-deps/spyder-kernels/spyder_kernels/console/start.py b/external-deps/spyder-kernels/spyder_kernels/console/start.py index 600b656c02e..b8a423af2a9 100644 --- a/external-deps/spyder-kernels/spyder_kernels/console/start.py +++ b/external-deps/spyder-kernels/spyder_kernels/console/start.py @@ -69,9 +69,6 @@ def kernel_config(): # Don't load nor save history in our IPython consoles. spy_cfg.HistoryAccessor.enabled = False - # Until we implement Issue 1052 - spy_cfg.InteractiveShell.xmode = 'Plain' - # Jedi completer. jedi_o = os.environ.get('SPY_JEDI_O') == 'True' spy_cfg.IPCompleter.use_jedi = jedi_o diff --git a/external-deps/spyder-kernels/spyder_kernels/console/tests/test_console_kernel.py b/external-deps/spyder-kernels/spyder_kernels/console/tests/test_console_kernel.py index f6f58c39b61..7e623b30107 100644 --- a/external-deps/spyder-kernels/spyder_kernels/console/tests/test_console_kernel.py +++ b/external-deps/spyder-kernels/spyder_kernels/console/tests/test_console_kernel.py @@ -1314,13 +1314,19 @@ def test_interrupt(): kernel_comm.remote_call().raise_interrupt_signal() # Wait for shell message while True: - assert time.time() - t0 < 5 + delta = time.time() - t0 + assert delta < 5 msg = client.get_shell_msg(timeout=TIMEOUT) if msg["parent_header"].get("msg_id") != msg_id: # not from my request continue break - assert time.time() - t0 < 5 + + delta = time.time() - t0 + assert delta < 5, ( + "10 seconds long call should have been interrupted, so the " + "interrupt signal was likely mishandled" + ) def test_enter_debug_after_interruption(): From 0927a4b54e7e96808bd3fc926e9dfe8e02b18c1b Mon Sep 17 00:00:00 2001 From: dalthviz <16781833+dalthviz@users.noreply.github.com> Date: Fri, 15 Nov 2024 23:38:47 -0500 Subject: [PATCH 05/19] IPython Console: Prevent premature call to config traceback highlight style --- spyder/plugins/ipythonconsole/widgets/shell.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spyder/plugins/ipythonconsole/widgets/shell.py b/spyder/plugins/ipythonconsole/widgets/shell.py index 19ee5505995..6183cd1ef3e 100644 --- a/spyder/plugins/ipythonconsole/widgets/shell.py +++ b/spyder/plugins/ipythonconsole/widgets/shell.py @@ -1439,6 +1439,8 @@ def _syntax_style_changed(self, changed=None): if self.syntax_style: self._highlighter._style = create_style_class(self.syntax_style) self._highlighter._clear_caches() + if changed is None: + return self.set_kernel_configuration( "traceback_highlight_style", self.syntax_style ) From 84b92b8446481dffe3144fea562e2d81143a80d3 Mon Sep 17 00:00:00 2001 From: dalthviz <16781833+dalthviz@users.noreply.github.com> Date: Sat, 16 Nov 2024 17:14:13 -0500 Subject: [PATCH 06/19] git subrepo pull --remote=https://github.com/dalthviz/spyder-kernels.git --branch=spyder_22965 --update --force external-deps/spyder-kernels subrepo: subdir: "external-deps/spyder-kernels" merged: "589c471ae" upstream: origin: "https://github.com/dalthviz/spyder-kernels.git" branch: "spyder_22965" commit: "589c471ae" git-subrepo: version: "0.4.3" origin: "???" commit: "???" --- external-deps/spyder-kernels/.gitrepo | 4 ++-- .../spyder_kernels/console/kernel.py | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/external-deps/spyder-kernels/.gitrepo b/external-deps/spyder-kernels/.gitrepo index 6130c65943f..a05a17b3a98 100644 --- a/external-deps/spyder-kernels/.gitrepo +++ b/external-deps/spyder-kernels/.gitrepo @@ -6,7 +6,7 @@ [subrepo] remote = https://github.com/dalthviz/spyder-kernels.git branch = spyder_22965 - commit = 75ebcac30e35d96658c59b70ee9c5f6b0cad8f98 - parent = 79dcad4c1c910dea5e75e23f7a30a7d585db55ba + commit = 589c471ae58a0480a0d670dbccc86d69a46630a7 + parent = 0927a4b54e7e96808bd3fc926e9dfe8e02b18c1b 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 e792bba8dfe..4f21e32cb36 100644 --- a/external-deps/spyder-kernels/spyder_kernels/console/kernel.py +++ b/external-deps/spyder-kernels/spyder_kernels/console/kernel.py @@ -662,13 +662,23 @@ def set_color_scheme(self, color_scheme): if color_scheme == "dark": # Needed to change the colors of tracebacks self.shell.run_line_magic("colors", "linux") - self.set_sympy_forecolor(background_color='dark') elif color_scheme == "light": self.shell.run_line_magic("colors", "lightbg") - self.set_sympy_forecolor(background_color='light') + self.set_sympy_forecolor(background_color=color_scheme) + self.set_traceback_highlighting(color_scheme) + + def set_traceback_highlighting(self, color_scheme): + """Set the traceback highlighting color.""" + color = 'bg:ansired' if color_scheme == 'dark' else 'bg:ansiyellow' + from IPython.core.ultratb import VerboseTB + + if getattr(VerboseTB, 'tb_highlight', None) is not None: + VerboseTB.tb_highlight = color + elif getattr(VerboseTB, '_tb_highlight', None) is not None: + VerboseTB._tb_highlight = color def set_traceback_syntax_highlighting(self, syntax_style): - """Set the traceback syntax highlighting.""" + """Set the traceback syntax highlighting style.""" try: import IPython.core.ultratb from IPython.core.ultratb import VerboseTB From 6c12cb15e425813035366d40567c0970dea4b197 Mon Sep 17 00:00:00 2001 From: dalthviz <16781833+dalthviz@users.noreply.github.com> Date: Sat, 16 Nov 2024 18:54:18 -0500 Subject: [PATCH 07/19] IPython Console: Enable traceback config from Spyder call to '_syntax_style_changed' --- spyder/plugins/ipythonconsole/widgets/shell.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spyder/plugins/ipythonconsole/widgets/shell.py b/spyder/plugins/ipythonconsole/widgets/shell.py index 6183cd1ef3e..12251484715 100644 --- a/spyder/plugins/ipythonconsole/widgets/shell.py +++ b/spyder/plugins/ipythonconsole/widgets/shell.py @@ -700,7 +700,7 @@ def set_color_scheme(self, color_scheme, reset=True): self.style_sheet, dark_color = create_qss_style(color_scheme) self.syntax_style = color_scheme self._style_sheet_changed() - self._syntax_style_changed() + self._syntax_style_changed(changed={}) if reset: self.reset(clear=True) if not self.spyder_kernel_ready: From ef967a462bea18899e1f1061ed8e55c6211237b2 Mon Sep 17 00:00:00 2001 From: dalthviz <16781833+dalthviz@users.noreply.github.com> Date: Tue, 19 Nov 2024 16:59:03 -0500 Subject: [PATCH 08/19] git subrepo pull --remote=https://github.com/dalthviz/spyder-kernels.git --branch=spyder_22965 --update --force external-deps/spyder-kernels subrepo: subdir: "external-deps/spyder-kernels" merged: "f3211825d" upstream: origin: "https://github.com/dalthviz/spyder-kernels.git" branch: "spyder_22965" commit: "f3211825d" git-subrepo: version: "0.4.3" origin: "???" commit: "???" --- external-deps/spyder-kernels/.gitrepo | 4 ++-- external-deps/spyder-kernels/spyder_kernels/console/kernel.py | 2 +- external-deps/spyder-kernels/spyder_kernels/customize/umr.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/external-deps/spyder-kernels/.gitrepo b/external-deps/spyder-kernels/.gitrepo index a05a17b3a98..011b52555df 100644 --- a/external-deps/spyder-kernels/.gitrepo +++ b/external-deps/spyder-kernels/.gitrepo @@ -6,7 +6,7 @@ [subrepo] remote = https://github.com/dalthviz/spyder-kernels.git branch = spyder_22965 - commit = 589c471ae58a0480a0d670dbccc86d69a46630a7 - parent = 0927a4b54e7e96808bd3fc926e9dfe8e02b18c1b + commit = f3211825d0bdb4970e14b930afffec164d275e26 + parent = 06fc0033cf021d6f2b1ad910e27029e2afe92e6e 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 4f21e32cb36..b54e7041e38 100644 --- a/external-deps/spyder-kernels/spyder_kernels/console/kernel.py +++ b/external-deps/spyder-kernels/spyder_kernels/console/kernel.py @@ -669,7 +669,7 @@ def set_color_scheme(self, color_scheme): def set_traceback_highlighting(self, color_scheme): """Set the traceback highlighting color.""" - color = 'bg:ansired' if color_scheme == 'dark' else 'bg:ansiyellow' + color = 'bg:ansigreen' if color_scheme == 'dark' else 'bg:ansiyellow' from IPython.core.ultratb import VerboseTB if getattr(VerboseTB, 'tb_highlight', None) is not None: diff --git a/external-deps/spyder-kernels/spyder_kernels/customize/umr.py b/external-deps/spyder-kernels/spyder_kernels/customize/umr.py index e779ec336bd..fc792d0cf58 100644 --- a/external-deps/spyder-kernels/spyder_kernels/customize/umr.py +++ b/external-deps/spyder-kernels/spyder_kernels/customize/umr.py @@ -92,7 +92,7 @@ def run(self): # Report reloaded modules if self.verbose and modnames_to_reload: modnames = modnames_to_reload - print("\x1b[4;33m%s\x1b[24m%s\x1b[0m" + print("\x1b[1;4;31m%s\x1b[24m%s\x1b[0m" % ("Reloaded modules", ": "+", ".join(modnames))) return modnames_to_reload From 23928f725ec8e6f44a3ca68ea2b2a4d7a5f8e70d Mon Sep 17 00:00:00 2001 From: dalthviz <16781833+dalthviz@users.noreply.github.com> Date: Tue, 19 Nov 2024 17:27:26 -0500 Subject: [PATCH 09/19] IPython Console: Pass syntax style dict to kernel config call --- spyder/plugins/ipythonconsole/widgets/shell.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spyder/plugins/ipythonconsole/widgets/shell.py b/spyder/plugins/ipythonconsole/widgets/shell.py index 57210d3e492..b2e64e999f9 100644 --- a/spyder/plugins/ipythonconsole/widgets/shell.py +++ b/spyder/plugins/ipythonconsole/widgets/shell.py @@ -1444,7 +1444,7 @@ def _syntax_style_changed(self, changed=None): if changed is None: return self.set_kernel_configuration( - "traceback_highlight_style", self.syntax_style + "traceback_highlight_style", self.syntax_style, get_color_scheme(self.syntax_style) ) else: self._highlighter.set_style_sheet(self.style_sheet) From 929b27e34daa7df52f56404d860c4831e0d4223a Mon Sep 17 00:00:00 2001 From: dalthviz <16781833+dalthviz@users.noreply.github.com> Date: Tue, 19 Nov 2024 17:27:49 -0500 Subject: [PATCH 10/19] git subrepo pull --remote=https://github.com/dalthviz/spyder-kernels.git --branch=spyder_22965 --update --force external-deps/spyder-kernels subrepo: subdir: "external-deps/spyder-kernels" merged: "d9e7bad05" upstream: origin: "https://github.com/dalthviz/spyder-kernels.git" branch: "spyder_22965" commit: "d9e7bad05" git-subrepo: version: "0.4.3" origin: "???" commit: "???" --- external-deps/spyder-kernels/.gitrepo | 4 +- .../spyder_kernels/console/kernel.py | 23 ++-- .../spyder_kernels/utils/style.py | 114 ++++++++++++++++++ 3 files changed, 125 insertions(+), 16 deletions(-) create mode 100644 external-deps/spyder-kernels/spyder_kernels/utils/style.py diff --git a/external-deps/spyder-kernels/.gitrepo b/external-deps/spyder-kernels/.gitrepo index 011b52555df..dbcc87c031c 100644 --- a/external-deps/spyder-kernels/.gitrepo +++ b/external-deps/spyder-kernels/.gitrepo @@ -6,7 +6,7 @@ [subrepo] remote = https://github.com/dalthviz/spyder-kernels.git branch = spyder_22965 - commit = f3211825d0bdb4970e14b930afffec164d275e26 - parent = 06fc0033cf021d6f2b1ad910e27029e2afe92e6e + commit = d9e7bad059f1acf69de9fef45c0b849aacfebf1e + parent = 23928f725ec8e6f44a3ca68ea2b2a4d7a5f8e70d 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 b54e7041e38..394fffe369a 100644 --- a/external-deps/spyder-kernels/spyder_kernels/console/kernel.py +++ b/external-deps/spyder-kernels/spyder_kernels/console/kernel.py @@ -677,24 +677,19 @@ def set_traceback_highlighting(self, color_scheme): elif getattr(VerboseTB, '_tb_highlight', None) is not None: VerboseTB._tb_highlight = color - def set_traceback_syntax_highlighting(self, syntax_style): + def set_traceback_syntax_highlighting(self, syntax_style, syntax_style_dict): """Set the traceback syntax highlighting style.""" - try: - import IPython.core.ultratb - from IPython.core.ultratb import VerboseTB + import IPython.core.ultratb + from IPython.core.ultratb import VerboseTB - from spyder.plugins.ipythonconsole.utils.style import create_style_class + from spyder_kernels.utils.style import create_style_class - IPython.core.ultratb.get_style_by_name = create_style_class + IPython.core.ultratb.get_style_by_name = create_style_class - if getattr(VerboseTB, 'tb_highlight_style', None) is not None: - VerboseTB.tb_highlight_style = syntax_style - elif getattr(VerboseTB, '_tb_highlight_style', None) is not None: - VerboseTB._tb_highlight_style = syntax_style - except Exception: - # Only usable if the kernel has access to Spyder syntax style function logic - # i.e spyder-kernels and Spyder are installed in the same environment - pass + if getattr(VerboseTB, 'tb_highlight_style', None) is not None: + VerboseTB.tb_highlight_style = syntax_style + elif getattr(VerboseTB, '_tb_highlight_style', None) is not None: + VerboseTB._tb_highlight_style = syntax_style def get_cwd(self): """Get current working directory.""" diff --git a/external-deps/spyder-kernels/spyder_kernels/utils/style.py b/external-deps/spyder-kernels/spyder_kernels/utils/style.py new file mode 100644 index 00000000000..9dde263f9e4 --- /dev/null +++ b/external-deps/spyder-kernels/spyder_kernels/utils/style.py @@ -0,0 +1,114 @@ +# -*- coding: utf-8 -*- +# ----------------------------------------------------------------------------- +# Copyright (c) 2009- Spyder Kernels Contributors +# +# Licensed under the terms of the MIT License +# (see spyder_kernels/__init__.py for details) +# ----------------------------------------------------------------------------- + +""" +Style for IPython Console +""" + +# Local imports +from spyder.config.gui import get_color_scheme + +# Third party imports +from pygments.style import Style +from pygments.token import (Name, Keyword, Comment, String, Number, + Punctuation, Operator) + + +def create_pygments_dict(color_scheme_dict): + """ + Create a dictionary that saves the given color scheme as a + Pygments style. + """ + + def give_font_weight(is_bold): + if is_bold: + return 'bold' + else: + return '' + + def give_font_style(is_italic): + if is_italic: + return 'italic' + else: + return '' + + color_scheme = get_color_scheme(color_scheme_dict) + + fon_c, fon_fw, fon_fs = color_scheme['normal'] + font_color = fon_c + font_font_weight = give_font_weight(fon_fw) + font_font_style = give_font_style(fon_fs) + key_c, key_fw, key_fs = color_scheme['keyword'] + keyword_color = key_c + keyword_font_weight = give_font_weight(key_fw) + keyword_font_style = give_font_style(key_fs) + bui_c, bui_fw, bui_fs = color_scheme['builtin'] + builtin_color = bui_c + builtin_font_weight = give_font_weight(bui_fw) + builtin_font_style = give_font_style(bui_fs) + str_c, str_fw, str_fs = color_scheme['string'] + string_color = str_c + string_font_weight = give_font_weight(str_fw) + string_font_style = give_font_style(str_fs) + num_c, num_fw, num_fs = color_scheme['number'] + number_color = num_c + number_font_weight = give_font_weight(num_fw) + number_font_style = give_font_style(num_fs) + com_c, com_fw, com_fs = color_scheme['comment'] + comment_color = com_c + comment_font_weight = give_font_weight(com_fw) + comment_font_style = give_font_style(com_fs) + def_c, def_fw, def_fs = color_scheme['definition'] + definition_color = def_c + definition_font_weight = give_font_weight(def_fw) + definition_font_style = give_font_style(def_fs) + ins_c, ins_fw, ins_fs = color_scheme['instance'] + instance_color = ins_c + instance_font_weight = give_font_weight(ins_fw) + instance_font_style = give_font_style(ins_fs) + + font_token = font_font_style + ' ' + font_font_weight + ' ' + font_color + definition_token = (definition_font_style + ' ' + definition_font_weight + + ' ' + definition_color) + builtin_token = (builtin_font_style + ' ' + builtin_font_weight + ' ' + + builtin_color) + instance_token = (instance_font_style + ' ' + instance_font_weight + ' ' + + instance_color) + keyword_token = (keyword_font_style + ' ' + keyword_font_weight + ' ' + + keyword_color) + comment_token = (comment_font_style + ' ' + comment_font_weight + ' ' + + comment_color) + string_token = (string_font_style + ' ' + string_font_weight + ' ' + + string_color) + number_token = (number_font_style + ' ' + number_font_weight + ' ' + + number_color) + + syntax_style_dic = {Name: font_token.strip(), + Name.Class: definition_token.strip(), + Name.Function: definition_token.strip(), + Name.Builtin: builtin_token.strip(), + Name.Builtin.Pseudo: instance_token.strip(), + Keyword: keyword_token.strip(), + Keyword.Type: builtin_token.strip(), + Comment: comment_token.strip(), + String: string_token.strip(), + Number: number_token.strip(), + Punctuation: font_token.strip(), + Operator.Word: keyword_token.strip()} + + return syntax_style_dic + + +def create_style_class(color_scheme_dict): + """Create a Pygments Style class with the given color scheme.""" + + class StyleClass(Style): + default_style = "" + styles = create_pygments_dict(color_scheme_dict) + + return StyleClass From 5baef983b540f87b5b0237f2d4b47ceb5ab6c1f9 Mon Sep 17 00:00:00 2001 From: dalthviz <16781833+dalthviz@users.noreply.github.com> Date: Tue, 19 Nov 2024 17:40:03 -0500 Subject: [PATCH 11/19] Testing --- spyder/plugins/ipythonconsole/widgets/shell.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spyder/plugins/ipythonconsole/widgets/shell.py b/spyder/plugins/ipythonconsole/widgets/shell.py index b2e64e999f9..f914e1470c3 100644 --- a/spyder/plugins/ipythonconsole/widgets/shell.py +++ b/spyder/plugins/ipythonconsole/widgets/shell.py @@ -1444,7 +1444,7 @@ def _syntax_style_changed(self, changed=None): if changed is None: return self.set_kernel_configuration( - "traceback_highlight_style", self.syntax_style, get_color_scheme(self.syntax_style) + "traceback_highlight_style", get_color_scheme(self.syntax_style) ) else: self._highlighter.set_style_sheet(self.style_sheet) From 0c5e18fa40331ce579e6206aeef5de89bb5dd6e1 Mon Sep 17 00:00:00 2001 From: dalthviz <16781833+dalthviz@users.noreply.github.com> Date: Tue, 19 Nov 2024 17:43:32 -0500 Subject: [PATCH 12/19] git subrepo pull --remote=https://github.com/dalthviz/spyder-kernels.git --branch=spyder_22965 --update --force external-deps/spyder-kernels subrepo: subdir: "external-deps/spyder-kernels" merged: "6939c42df" upstream: origin: "https://github.com/dalthviz/spyder-kernels.git" branch: "spyder_22965" commit: "6939c42df" git-subrepo: version: "0.4.3" origin: "???" commit: "???" --- external-deps/spyder-kernels/.gitrepo | 4 ++-- external-deps/spyder-kernels/spyder_kernels/console/kernel.py | 2 +- external-deps/spyder-kernels/spyder_kernels/utils/style.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/external-deps/spyder-kernels/.gitrepo b/external-deps/spyder-kernels/.gitrepo index dbcc87c031c..490f5fa67f5 100644 --- a/external-deps/spyder-kernels/.gitrepo +++ b/external-deps/spyder-kernels/.gitrepo @@ -6,7 +6,7 @@ [subrepo] remote = https://github.com/dalthviz/spyder-kernels.git branch = spyder_22965 - commit = d9e7bad059f1acf69de9fef45c0b849aacfebf1e - parent = 23928f725ec8e6f44a3ca68ea2b2a4d7a5f8e70d + commit = 6939c42dfe1500ce1fa99a079d4fe7bffab90ddb + parent = 5baef983b540f87b5b0237f2d4b47ceb5ab6c1f9 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 394fffe369a..e522237ef4a 100644 --- a/external-deps/spyder-kernels/spyder_kernels/console/kernel.py +++ b/external-deps/spyder-kernels/spyder_kernels/console/kernel.py @@ -677,7 +677,7 @@ def set_traceback_highlighting(self, color_scheme): elif getattr(VerboseTB, '_tb_highlight', None) is not None: VerboseTB._tb_highlight = color - def set_traceback_syntax_highlighting(self, syntax_style, syntax_style_dict): + def set_traceback_syntax_highlighting(self, syntax_style): """Set the traceback syntax highlighting style.""" import IPython.core.ultratb from IPython.core.ultratb import VerboseTB diff --git a/external-deps/spyder-kernels/spyder_kernels/utils/style.py b/external-deps/spyder-kernels/spyder_kernels/utils/style.py index 9dde263f9e4..f4b4c227a4b 100644 --- a/external-deps/spyder-kernels/spyder_kernels/utils/style.py +++ b/external-deps/spyder-kernels/spyder_kernels/utils/style.py @@ -109,6 +109,6 @@ def create_style_class(color_scheme_dict): class StyleClass(Style): default_style = "" - styles = create_pygments_dict(color_scheme_dict) + styles = create_pygments_dict(dict(color_scheme_dict)) return StyleClass From d0be46014ce9d433dd8fd8f0290de35649e5b5fe Mon Sep 17 00:00:00 2001 From: dalthviz <16781833+dalthviz@users.noreply.github.com> Date: Tue, 19 Nov 2024 17:50:05 -0500 Subject: [PATCH 13/19] git subrepo pull --remote=https://github.com/dalthviz/spyder-kernels.git --branch=spyder_22965 --update --force external-deps/spyder-kernels subrepo: subdir: "external-deps/spyder-kernels" merged: "753558ad1" upstream: origin: "https://github.com/dalthviz/spyder-kernels.git" branch: "spyder_22965" commit: "753558ad1" git-subrepo: version: "0.4.3" origin: "???" commit: "???" --- external-deps/spyder-kernels/.gitrepo | 4 ++-- external-deps/spyder-kernels/spyder_kernels/utils/style.py | 5 +---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/external-deps/spyder-kernels/.gitrepo b/external-deps/spyder-kernels/.gitrepo index 490f5fa67f5..51d7a6c0dfe 100644 --- a/external-deps/spyder-kernels/.gitrepo +++ b/external-deps/spyder-kernels/.gitrepo @@ -6,7 +6,7 @@ [subrepo] remote = https://github.com/dalthviz/spyder-kernels.git branch = spyder_22965 - commit = 6939c42dfe1500ce1fa99a079d4fe7bffab90ddb - parent = 5baef983b540f87b5b0237f2d4b47ceb5ab6c1f9 + commit = 753558ad1a63a3a92a15642b730481beb55353a7 + parent = 0c5e18fa40331ce579e6206aeef5de89bb5dd6e1 method = merge cmdver = 0.4.3 diff --git a/external-deps/spyder-kernels/spyder_kernels/utils/style.py b/external-deps/spyder-kernels/spyder_kernels/utils/style.py index f4b4c227a4b..6ac0e2c3d1e 100644 --- a/external-deps/spyder-kernels/spyder_kernels/utils/style.py +++ b/external-deps/spyder-kernels/spyder_kernels/utils/style.py @@ -10,9 +10,6 @@ Style for IPython Console """ -# Local imports -from spyder.config.gui import get_color_scheme - # Third party imports from pygments.style import Style from pygments.token import (Name, Keyword, Comment, String, Number, @@ -37,7 +34,7 @@ def give_font_style(is_italic): else: return '' - color_scheme = get_color_scheme(color_scheme_dict) + color_scheme = color_scheme_dict fon_c, fon_fw, fon_fs = color_scheme['normal'] font_color = fon_c From 8e0d158e5166b9036ff54f6f7c7d2324eee48609 Mon Sep 17 00:00:00 2001 From: dalthviz <16781833+dalthviz@users.noreply.github.com> Date: Tue, 19 Nov 2024 17:52:57 -0500 Subject: [PATCH 14/19] git subrepo pull --remote=https://github.com/dalthviz/spyder-kernels.git --branch=spyder_22965 --update --force external-deps/spyder-kernels subrepo: subdir: "external-deps/spyder-kernels" merged: "07b9ca3e8" upstream: origin: "https://github.com/dalthviz/spyder-kernels.git" branch: "spyder_22965" commit: "07b9ca3e8" git-subrepo: version: "0.4.3" origin: "???" commit: "???" --- external-deps/spyder-kernels/.gitrepo | 4 ++-- external-deps/spyder-kernels/spyder_kernels/utils/style.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/external-deps/spyder-kernels/.gitrepo b/external-deps/spyder-kernels/.gitrepo index 51d7a6c0dfe..f2ebb01b0ae 100644 --- a/external-deps/spyder-kernels/.gitrepo +++ b/external-deps/spyder-kernels/.gitrepo @@ -6,7 +6,7 @@ [subrepo] remote = https://github.com/dalthviz/spyder-kernels.git branch = spyder_22965 - commit = 753558ad1a63a3a92a15642b730481beb55353a7 - parent = 0c5e18fa40331ce579e6206aeef5de89bb5dd6e1 + commit = 07b9ca3e8d08f64c95c0c15f79a31183363c294a + parent = d0be46014ce9d433dd8fd8f0290de35649e5b5fe method = merge cmdver = 0.4.3 diff --git a/external-deps/spyder-kernels/spyder_kernels/utils/style.py b/external-deps/spyder-kernels/spyder_kernels/utils/style.py index 6ac0e2c3d1e..f4dc70c9523 100644 --- a/external-deps/spyder-kernels/spyder_kernels/utils/style.py +++ b/external-deps/spyder-kernels/spyder_kernels/utils/style.py @@ -106,6 +106,6 @@ def create_style_class(color_scheme_dict): class StyleClass(Style): default_style = "" - styles = create_pygments_dict(dict(color_scheme_dict)) + styles = create_pygments_dict(color_scheme_dict) return StyleClass From a067c565d846359fee4c21502dab5646032007ea Mon Sep 17 00:00:00 2001 From: dalthviz <16781833+dalthviz@users.noreply.github.com> Date: Wed, 20 Nov 2024 18:10:00 -0500 Subject: [PATCH 15/19] git subrepo pull --remote=https://github.com/dalthviz/spyder-kernels.git --branch=spyder_22965 --update --force external-deps/spyder-kernels subrepo: subdir: "external-deps/spyder-kernels" merged: "db71627b9" upstream: origin: "https://github.com/dalthviz/spyder-kernels.git" branch: "spyder_22965" commit: "db71627b9" git-subrepo: version: "0.4.3" origin: "???" commit: "???" --- external-deps/spyder-kernels/.gitrepo | 4 +- .../spyder_kernels/console/kernel.py | 11 +- .../spyder_kernels/console/shell.py | 14 ++ .../spyder_kernels/customize/code_runner.py | 5 +- .../spyder_kernels/customize/umr.py | 11 +- .../spyder_kernels/utils/style.py | 127 +++++++++++------- 6 files changed, 107 insertions(+), 65 deletions(-) diff --git a/external-deps/spyder-kernels/.gitrepo b/external-deps/spyder-kernels/.gitrepo index f2ebb01b0ae..483634e88a7 100644 --- a/external-deps/spyder-kernels/.gitrepo +++ b/external-deps/spyder-kernels/.gitrepo @@ -6,7 +6,7 @@ [subrepo] remote = https://github.com/dalthviz/spyder-kernels.git branch = spyder_22965 - commit = 07b9ca3e8d08f64c95c0c15f79a31183363c294a - parent = d0be46014ce9d433dd8fd8f0290de35649e5b5fe + commit = db71627b92c61142688a12d1148732e5cfafc159 + parent = a6cb0c2c351cbdddac08e9063d508c16fdfacead 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 e522237ef4a..391c7392b24 100644 --- a/external-deps/spyder-kernels/spyder_kernels/console/kernel.py +++ b/external-deps/spyder-kernels/spyder_kernels/console/kernel.py @@ -47,6 +47,7 @@ from spyder_kernels.utils.mpl import automatic_backend, MPL_BACKENDS_TO_SPYDER from spyder_kernels.utils.nsview import ( get_remote_data, make_remote_view, get_size) +from spyder_kernels.utils.style import create_style_class from spyder_kernels.console.shell import SpyderShell from spyder_kernels.comms.utils import WriteContext @@ -659,17 +660,13 @@ def set_configuration(self, conf): return ret def set_color_scheme(self, color_scheme): - if color_scheme == "dark": - # Needed to change the colors of tracebacks - self.shell.run_line_magic("colors", "linux") - elif color_scheme == "light": - self.shell.run_line_magic("colors", "lightbg") + self.shell.set_spyder_theme(color_scheme) self.set_sympy_forecolor(background_color=color_scheme) self.set_traceback_highlighting(color_scheme) def set_traceback_highlighting(self, color_scheme): """Set the traceback highlighting color.""" - color = 'bg:ansigreen' if color_scheme == 'dark' else 'bg:ansiyellow' + color = 'bg:ansired' if color_scheme == 'dark' else 'bg:ansiyellow' from IPython.core.ultratb import VerboseTB if getattr(VerboseTB, 'tb_highlight', None) is not None: @@ -682,8 +679,6 @@ def set_traceback_syntax_highlighting(self, syntax_style): import IPython.core.ultratb from IPython.core.ultratb import VerboseTB - from spyder_kernels.utils.style import create_style_class - IPython.core.ultratb.get_style_by_name = create_style_class if getattr(VerboseTB, 'tb_highlight_style', None) is not None: diff --git a/external-deps/spyder-kernels/spyder_kernels/console/shell.py b/external-deps/spyder-kernels/spyder_kernels/console/shell.py index 3e9224c9df6..0de22d4345b 100644 --- a/external-deps/spyder-kernels/spyder_kernels/console/shell.py +++ b/external-deps/spyder-kernels/spyder_kernels/console/shell.py @@ -56,6 +56,7 @@ def __init__(self, *args, **kwargs): self._allow_kbdint = False self.register_debugger_sigint() self.update_gui_frontend = False + self._spyder_theme = 'dark' # register post_execute self.events.register('post_execute', self.do_post_execute) @@ -84,6 +85,19 @@ def _showtraceback(self, etype, evalue, stb): stb = [''] super(SpyderShell, self)._showtraceback(etype, evalue, stb) + def set_spyder_theme(self, theme): + """Set the theme for the console.""" + self._spyder_theme = theme + if theme == "dark": + # Needed to change the colors of tracebacks + self.run_line_magic("colors", "linux") + elif theme == "light": + self.run_line_magic("colors", "lightbg") + + def get_spyder_theme(self): + """Get the theme for the console.""" + return self._spyder_theme + def enable_matplotlib(self, gui=None): """Enable matplotlib.""" if gui is None or gui.lower() == "auto": diff --git a/external-deps/spyder-kernels/spyder_kernels/customize/code_runner.py b/external-deps/spyder-kernels/spyder_kernels/customize/code_runner.py index 9917abb9999..b47a309f52f 100644 --- a/external-deps/spyder-kernels/spyder_kernels/customize/code_runner.py +++ b/external-deps/spyder-kernels/spyder_kernels/customize/code_runner.py @@ -145,10 +145,11 @@ class SpyderCodeRunner(Magics): def __init__(self, *args, **kwargs): self.show_global_msg = True self.show_invalid_syntax_msg = True + super().__init__(*args, **kwargs) self.umr = UserModuleReloader( - namelist=os.environ.get("SPY_UMR_NAMELIST", None) + namelist=os.environ.get("SPY_UMR_NAMELIST", None), + shell=self.shell, ) - super().__init__(*args, **kwargs) @runfile_arguments @needs_local_scope diff --git a/external-deps/spyder-kernels/spyder_kernels/customize/umr.py b/external-deps/spyder-kernels/spyder_kernels/customize/umr.py index fc792d0cf58..d4842bca31c 100644 --- a/external-deps/spyder-kernels/spyder_kernels/customize/umr.py +++ b/external-deps/spyder-kernels/spyder_kernels/customize/umr.py @@ -20,7 +20,7 @@ class UserModuleReloader: namelist [list]: blacklist in terms of module name """ - def __init__(self, namelist=None, pathlist=None): + def __init__(self, namelist=None, pathlist=None, shell=None): if namelist is None: namelist = [] else: @@ -45,6 +45,7 @@ def __init__(self, namelist=None, pathlist=None): self.namelist = namelist + spy_modules + mpl_modules + other_modules self.pathlist = pathlist + self._shell = shell # List of previously loaded modules self.previous_modules = list(sys.modules.keys()) @@ -92,7 +93,11 @@ def run(self): # Report reloaded modules if self.verbose and modnames_to_reload: modnames = modnames_to_reload - print("\x1b[1;4;31m%s\x1b[24m%s\x1b[0m" - % ("Reloaded modules", ": "+", ".join(modnames))) + colors = {"dark": "33", "light": "31"} + color = colors["dark"] + if self._shell: + color = colors[self._shell.get_spyder_theme()] + print("\x1b[4;%sm%s\x1b[24m%s\x1b[0m" + % (color, "Reloaded modules", ": "+", ".join(modnames))) return modnames_to_reload diff --git a/external-deps/spyder-kernels/spyder_kernels/utils/style.py b/external-deps/spyder-kernels/spyder_kernels/utils/style.py index f4dc70c9523..255ce9593da 100644 --- a/external-deps/spyder-kernels/spyder_kernels/utils/style.py +++ b/external-deps/spyder-kernels/spyder_kernels/utils/style.py @@ -12,8 +12,15 @@ # Third party imports from pygments.style import Style -from pygments.token import (Name, Keyword, Comment, String, Number, - Punctuation, Operator) +from pygments.token import ( + Name, + Keyword, + Comment, + String, + Number, + Punctuation, + Operator, +) def create_pygments_dict(color_scheme_dict): @@ -24,79 +31,99 @@ def create_pygments_dict(color_scheme_dict): def give_font_weight(is_bold): if is_bold: - return 'bold' + return "bold" else: - return '' + return "" def give_font_style(is_italic): if is_italic: - return 'italic' + return "italic" else: - return '' + return "" color_scheme = color_scheme_dict - fon_c, fon_fw, fon_fs = color_scheme['normal'] - font_color = fon_c + fon_c, fon_fw, fon_fs = color_scheme["normal"] + font_color = fon_c font_font_weight = give_font_weight(fon_fw) font_font_style = give_font_style(fon_fs) - key_c, key_fw, key_fs = color_scheme['keyword'] - keyword_color = key_c + + key_c, key_fw, key_fs = color_scheme["keyword"] + keyword_color = key_c keyword_font_weight = give_font_weight(key_fw) keyword_font_style = give_font_style(key_fs) - bui_c, bui_fw, bui_fs = color_scheme['builtin'] - builtin_color = bui_c + + bui_c, bui_fw, bui_fs = color_scheme["builtin"] + builtin_color = bui_c builtin_font_weight = give_font_weight(bui_fw) builtin_font_style = give_font_style(bui_fs) - str_c, str_fw, str_fs = color_scheme['string'] - string_color = str_c + + str_c, str_fw, str_fs = color_scheme["string"] + string_color = str_c string_font_weight = give_font_weight(str_fw) string_font_style = give_font_style(str_fs) - num_c, num_fw, num_fs = color_scheme['number'] - number_color = num_c + + num_c, num_fw, num_fs = color_scheme["number"] + number_color = num_c number_font_weight = give_font_weight(num_fw) number_font_style = give_font_style(num_fs) - com_c, com_fw, com_fs = color_scheme['comment'] - comment_color = com_c + + com_c, com_fw, com_fs = color_scheme["comment"] + comment_color = com_c comment_font_weight = give_font_weight(com_fw) comment_font_style = give_font_style(com_fs) - def_c, def_fw, def_fs = color_scheme['definition'] - definition_color = def_c + + def_c, def_fw, def_fs = color_scheme["definition"] + definition_color = def_c definition_font_weight = give_font_weight(def_fw) definition_font_style = give_font_style(def_fs) - ins_c, ins_fw, ins_fs = color_scheme['instance'] - instance_color = ins_c + + ins_c, ins_fw, ins_fs = color_scheme["instance"] + instance_color = ins_c instance_font_weight = give_font_weight(ins_fw) instance_font_style = give_font_style(ins_fs) - font_token = font_font_style + ' ' + font_font_weight + ' ' + font_color - definition_token = (definition_font_style + ' ' + definition_font_weight + - ' ' + definition_color) - builtin_token = (builtin_font_style + ' ' + builtin_font_weight + ' ' + - builtin_color) - instance_token = (instance_font_style + ' ' + instance_font_weight + ' ' + - instance_color) - keyword_token = (keyword_font_style + ' ' + keyword_font_weight + ' ' + - keyword_color) - comment_token = (comment_font_style + ' ' + comment_font_weight + ' ' + - comment_color) - string_token = (string_font_style + ' ' + string_font_weight + ' ' + - string_color) - number_token = (number_font_style + ' ' + number_font_weight + ' ' + - number_color) - - syntax_style_dic = {Name: font_token.strip(), - Name.Class: definition_token.strip(), - Name.Function: definition_token.strip(), - Name.Builtin: builtin_token.strip(), - Name.Builtin.Pseudo: instance_token.strip(), - Keyword: keyword_token.strip(), - Keyword.Type: builtin_token.strip(), - Comment: comment_token.strip(), - String: string_token.strip(), - Number: number_token.strip(), - Punctuation: font_token.strip(), - Operator.Word: keyword_token.strip()} + font_token = font_font_style + " " + font_font_weight + " " + font_color + definition_token = ( + definition_font_style + + " " + + definition_font_weight + + " " + + definition_color + ) + builtin_token = ( + builtin_font_style + " " + builtin_font_weight + " " + builtin_color + ) + instance_token = ( + instance_font_style + " " + instance_font_weight + " " + instance_color + ) + keyword_token = ( + keyword_font_style + " " + keyword_font_weight + " " + keyword_color + ) + comment_token = ( + comment_font_style + " " + comment_font_weight + " " + comment_color + ) + string_token = ( + string_font_style + " " + string_font_weight + " " + string_color + ) + number_token = ( + number_font_style + " " + number_font_weight + " " + number_color + ) + + syntax_style_dic = { + Name: font_token.strip(), + Name.Class: definition_token.strip(), + Name.Function: definition_token.strip(), + Name.Builtin: builtin_token.strip(), + Name.Builtin.Pseudo: instance_token.strip(), + Keyword: keyword_token.strip(), + Keyword.Type: builtin_token.strip(), + Comment: comment_token.strip(), + String: string_token.strip(), + Number: number_token.strip(), + Punctuation: font_token.strip(), + Operator.Word: keyword_token.strip(), + } return syntax_style_dic From 55d747c958ad4fb8b32ea78a0a39f072e8c01c3b Mon Sep 17 00:00:00 2001 From: dalthviz <16781833+dalthviz@users.noreply.github.com> Date: Wed, 20 Nov 2024 18:14:05 -0500 Subject: [PATCH 16/19] Code style --- spyder/plugins/ipythonconsole/widgets/shell.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spyder/plugins/ipythonconsole/widgets/shell.py b/spyder/plugins/ipythonconsole/widgets/shell.py index f914e1470c3..1bdf62df8a8 100644 --- a/spyder/plugins/ipythonconsole/widgets/shell.py +++ b/spyder/plugins/ipythonconsole/widgets/shell.py @@ -1444,7 +1444,8 @@ def _syntax_style_changed(self, changed=None): if changed is None: return self.set_kernel_configuration( - "traceback_highlight_style", get_color_scheme(self.syntax_style) + "traceback_highlight_style", + get_color_scheme(self.syntax_style), ) else: self._highlighter.set_style_sheet(self.style_sheet) From 09750eaea9bbeee252e5d43417b6d01b18000765 Mon Sep 17 00:00:00 2001 From: dalthviz <16781833+dalthviz@users.noreply.github.com> Date: Thu, 21 Nov 2024 18:39:12 -0500 Subject: [PATCH 17/19] git subrepo pull --remote=https://github.com/dalthviz/spyder-kernels.git --branch=spyder_22965 --update --force external-deps/spyder-kernels subrepo: subdir: "external-deps/spyder-kernels" merged: "20f181681" upstream: origin: "https://github.com/dalthviz/spyder-kernels.git" branch: "spyder_22965" commit: "20f181681" git-subrepo: version: "0.4.3" origin: "???" commit: "???" --- external-deps/spyder-kernels/.gitrepo | 4 ++-- .../spyder-kernels/spyder_kernels/customize/code_runner.py | 3 ++- external-deps/spyder-kernels/spyder_kernels/customize/umr.py | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/external-deps/spyder-kernels/.gitrepo b/external-deps/spyder-kernels/.gitrepo index 483634e88a7..2960ae046c9 100644 --- a/external-deps/spyder-kernels/.gitrepo +++ b/external-deps/spyder-kernels/.gitrepo @@ -6,7 +6,7 @@ [subrepo] remote = https://github.com/dalthviz/spyder-kernels.git branch = spyder_22965 - commit = db71627b92c61142688a12d1148732e5cfafc159 - parent = a6cb0c2c351cbdddac08e9063d508c16fdfacead + commit = 20f181681e4b7fa4c18d6820f6802cdc63d53c32 + parent = 55d747c958ad4fb8b32ea78a0a39f072e8c01c3b method = merge cmdver = 0.4.3 diff --git a/external-deps/spyder-kernels/spyder_kernels/customize/code_runner.py b/external-deps/spyder-kernels/spyder_kernels/customize/code_runner.py index b47a309f52f..8f3ac12cf41 100644 --- a/external-deps/spyder-kernels/spyder_kernels/customize/code_runner.py +++ b/external-deps/spyder-kernels/spyder_kernels/customize/code_runner.py @@ -143,9 +143,10 @@ class SpyderCodeRunner(Magics): Functions and magics related to code execution, debugging, profiling, etc. """ def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.show_global_msg = True self.show_invalid_syntax_msg = True - super().__init__(*args, **kwargs) self.umr = UserModuleReloader( namelist=os.environ.get("SPY_UMR_NAMELIST", None), shell=self.shell, diff --git a/external-deps/spyder-kernels/spyder_kernels/customize/umr.py b/external-deps/spyder-kernels/spyder_kernels/customize/umr.py index d4842bca31c..c110515823d 100644 --- a/external-deps/spyder-kernels/spyder_kernels/customize/umr.py +++ b/external-deps/spyder-kernels/spyder_kernels/customize/umr.py @@ -97,7 +97,7 @@ def run(self): color = colors["dark"] if self._shell: color = colors[self._shell.get_spyder_theme()] - print("\x1b[4;%sm%s\x1b[24m%s\x1b[0m" - % (color, "Reloaded modules", ": "+", ".join(modnames))) + content = ": "+", ".join(modnames) + print(f"\x1b[4;{color}mReloaded modules\x1b[24m{content}\x1b[0m") return modnames_to_reload From 41c288acf1c34b7cd9f1175b4f0fa8233692a26c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Althviz=20Mor=C3=A9?= <16781833+dalthviz@users.noreply.github.com> Date: Tue, 26 Nov 2024 17:15:15 -0500 Subject: [PATCH 18/19] Apply suggestions from code review Co-authored-by: Carlos Cordoba --- spyder/plugins/ipythonconsole/widgets/shell.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spyder/plugins/ipythonconsole/widgets/shell.py b/spyder/plugins/ipythonconsole/widgets/shell.py index 1bdf62df8a8..4a25586c386 100644 --- a/spyder/plugins/ipythonconsole/widgets/shell.py +++ b/spyder/plugins/ipythonconsole/widgets/shell.py @@ -187,8 +187,9 @@ def __init__( self.is_kernel_configured = False self._init_kernel_setup = False self._is_banner_shown = False - # Set bright colors instead of bold formating for better traceback - # readability + + # Set bright colors instead of bold formatting for better traceback + # readability. self._ansi_processor.bold_text_enabled = False if handlers is None: From 5dd2016a165a9df372c342b4a96f9d76bae0127b Mon Sep 17 00:00:00 2001 From: dalthviz <16781833+dalthviz@users.noreply.github.com> Date: Tue, 26 Nov 2024 17:20:08 -0500 Subject: [PATCH 19/19] git subrepo pull (merge) --remote=https://github.com/spyder-ide/spyder-kernels.git --branch=master --update --force external-deps/spyder-kernels subrepo: subdir: "external-deps/spyder-kernels" merged: "07f24b6fd" upstream: origin: "https://github.com/spyder-ide/spyder-kernels.git" branch: "master" commit: "07f24b6fd" git-subrepo: version: "0.4.3" origin: "???" commit: "???" --- 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 2960ae046c9..4f04f00a36f 100644 --- a/external-deps/spyder-kernels/.gitrepo +++ b/external-deps/spyder-kernels/.gitrepo @@ -4,9 +4,9 @@ ; git-subrepo command. See https://github.com/ingydotnet/git-subrepo#readme ; [subrepo] - remote = https://github.com/dalthviz/spyder-kernels.git - branch = spyder_22965 - commit = 20f181681e4b7fa4c18d6820f6802cdc63d53c32 - parent = 55d747c958ad4fb8b32ea78a0a39f072e8c01c3b + remote = https://github.com/spyder-ide/spyder-kernels.git + branch = master + commit = 07f24b6fde55585e64d1802036efba19514dbf0c + parent = 41c288acf1c34b7cd9f1175b4f0fa8233692a26c method = merge cmdver = 0.4.3