From 75ebcac30e35d96658c59b70ee9c5f6b0cad8f98 Mon Sep 17 00:00:00 2001 From: dalthviz <16781833+dalthviz@users.noreply.github.com> Date: Fri, 15 Nov 2024 23:20:14 -0500 Subject: [PATCH 1/8] Add logic to handle configuring tracebacks highlight style --- spyder_kernels/console/kernel.py | 21 +++++++++++++++++++++ spyder_kernels/console/start.py | 3 --- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/spyder_kernels/console/kernel.py b/spyder_kernels/console/kernel.py index ad16c084..e792bba8 100644 --- a/spyder_kernels/console/kernel.py +++ b/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/spyder_kernels/console/start.py b/spyder_kernels/console/start.py index 600b656c..b8a423af 100644 --- a/spyder_kernels/console/start.py +++ b/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 From 589c471ae58a0480a0d670dbccc86d69a46630a7 Mon Sep 17 00:00:00 2001 From: dalthviz <16781833+dalthviz@users.noreply.github.com> Date: Sat, 16 Nov 2024 17:05:38 -0500 Subject: [PATCH 2/8] Add method to config tracebacks highlighting color --- spyder_kernels/console/kernel.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/spyder_kernels/console/kernel.py b/spyder_kernels/console/kernel.py index e792bba8..4f21e32c 100644 --- a/spyder_kernels/console/kernel.py +++ b/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 f3211825d0bdb4970e14b930afffec164d275e26 Mon Sep 17 00:00:00 2001 From: dalthviz <16781833+dalthviz@users.noreply.github.com> Date: Tue, 19 Nov 2024 16:55:30 -0500 Subject: [PATCH 3/8] Update colors for reloaded modules list and for traceback highlight --- spyder_kernels/console/kernel.py | 2 +- spyder_kernels/customize/umr.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spyder_kernels/console/kernel.py b/spyder_kernels/console/kernel.py index 4f21e32c..b54e7041 100644 --- a/spyder_kernels/console/kernel.py +++ b/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/spyder_kernels/customize/umr.py b/spyder_kernels/customize/umr.py index e779ec33..fc792d0c 100644 --- a/spyder_kernels/customize/umr.py +++ b/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 07b9ca3e8d08f64c95c0c15f79a31183363c294a Mon Sep 17 00:00:00 2001 From: dalthviz <16781833+dalthviz@users.noreply.github.com> Date: Tue, 19 Nov 2024 17:26:37 -0500 Subject: [PATCH 4/8] Add style module --- spyder_kernels/console/kernel.py | 21 +++--- spyder_kernels/utils/style.py | 111 +++++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+), 13 deletions(-) create mode 100644 spyder_kernels/utils/style.py diff --git a/spyder_kernels/console/kernel.py b/spyder_kernels/console/kernel.py index b54e7041..e522237e 100644 --- a/spyder_kernels/console/kernel.py +++ b/spyder_kernels/console/kernel.py @@ -679,22 +679,17 @@ def set_traceback_highlighting(self, color_scheme): def set_traceback_syntax_highlighting(self, syntax_style): """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/spyder_kernels/utils/style.py b/spyder_kernels/utils/style.py new file mode 100644 index 00000000..f4dc70c9 --- /dev/null +++ b/spyder_kernels/utils/style.py @@ -0,0 +1,111 @@ +# -*- 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 +""" + +# 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 = 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 584cc8dd6cf32628ee20807227e450642f2ea661 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Althviz=20Mor=C3=A9?= <16781833+dalthviz@users.noreply.github.com> Date: Wed, 20 Nov 2024 16:54:36 -0500 Subject: [PATCH 5/8] Apply suggestions from code review Co-authored-by: Carlos Cordoba --- spyder_kernels/utils/style.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/spyder_kernels/utils/style.py b/spyder_kernels/utils/style.py index f4dc70c9..548b04fe 100644 --- a/spyder_kernels/utils/style.py +++ b/spyder_kernels/utils/style.py @@ -40,30 +40,37 @@ def give_font_style(is_italic): 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) From db71627b92c61142688a12d1148732e5cfafc159 Mon Sep 17 00:00:00 2001 From: dalthviz <16781833+dalthviz@users.noreply.github.com> Date: Wed, 20 Nov 2024 17:34:00 -0500 Subject: [PATCH 6/8] style.py file format and UMR message colors handling --- 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 | 120 ++++++++++++++---------- 5 files changed, 98 insertions(+), 63 deletions(-) diff --git a/spyder_kernels/console/kernel.py b/spyder_kernels/console/kernel.py index e522237e..391c7392 100644 --- a/spyder_kernels/console/kernel.py +++ b/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/spyder_kernels/console/shell.py b/spyder_kernels/console/shell.py index 3e9224c9..0de22d43 100644 --- a/spyder_kernels/console/shell.py +++ b/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/spyder_kernels/customize/code_runner.py b/spyder_kernels/customize/code_runner.py index 9917abb9..b47a309f 100644 --- a/spyder_kernels/customize/code_runner.py +++ b/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/spyder_kernels/customize/umr.py b/spyder_kernels/customize/umr.py index fc792d0c..d4842bca 100644 --- a/spyder_kernels/customize/umr.py +++ b/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/spyder_kernels/utils/style.py b/spyder_kernels/utils/style.py index 548b04fe..255ce959 100644 --- a/spyder_kernels/utils/style.py +++ b/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,86 +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 83b61ac2af8228c052cd001f16f03d9c1b3eec72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Althviz=20Mor=C3=A9?= <16781833+dalthviz@users.noreply.github.com> Date: Thu, 21 Nov 2024 18:26:21 -0500 Subject: [PATCH 7/8] Apply suggestions from code review Co-authored-by: Carlos Cordoba --- spyder_kernels/customize/code_runner.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spyder_kernels/customize/code_runner.py b/spyder_kernels/customize/code_runner.py index b47a309f..8f3ac12c 100644 --- a/spyder_kernels/customize/code_runner.py +++ b/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, From 20f181681e4b7fa4c18d6820f6802cdc63d53c32 Mon Sep 17 00:00:00 2001 From: dalthviz <16781833+dalthviz@users.noreply.github.com> Date: Thu, 21 Nov 2024 18:36:51 -0500 Subject: [PATCH 8/8] Use f-string for the 'Reloaded modules' message --- spyder_kernels/customize/umr.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spyder_kernels/customize/umr.py b/spyder_kernels/customize/umr.py index d4842bca..c1105158 100644 --- a/spyder_kernels/customize/umr.py +++ b/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