|
27 | 27 | from ipykernel.ipkernel import IPythonKernel |
28 | 28 | from ipykernel import get_connection_info |
29 | 29 | from IPython.core import release as ipython_release |
| 30 | +from packaging.version import parse as parse_version |
30 | 31 | from traitlets.config.loader import Config, LazyConfigValue |
31 | 32 | import zmq |
32 | 33 | from zmq.utils.garbage import gc |
|
49 | 50 | from spyder_kernels.utils.mpl import automatic_backend, MPL_BACKENDS_TO_SPYDER |
50 | 51 | from spyder_kernels.utils.nsview import ( |
51 | 52 | get_remote_data, make_remote_view, get_size) |
52 | | -from spyder_kernels.utils.style import create_style_class |
| 53 | +from spyder_kernels.utils.style import create_pygments_dict, create_style_class |
53 | 54 | from spyder_kernels.console.shell import SpyderShell |
54 | 55 | from spyder_kernels.comms.utils import WriteContext |
55 | 56 |
|
@@ -705,15 +706,37 @@ def set_traceback_highlighting(self, color_scheme): |
705 | 706 |
|
706 | 707 | def set_traceback_syntax_highlighting(self, syntax_style): |
707 | 708 | """Set the traceback syntax highlighting style.""" |
708 | | - import IPython.core.ultratb |
709 | | - from IPython.core.ultratb import VerboseTB |
| 709 | + if parse_version(ipython_release.version) >= parse_version("9.0"): |
| 710 | + # Create spyder theme definition and set it (IPython 9.x+) |
| 711 | + import IPython.utils.PyColorize |
| 712 | + from IPython.utils.PyColorize import ( |
| 713 | + Theme, |
| 714 | + linux_theme, |
| 715 | + neutral_theme, |
| 716 | + ) |
| 717 | + |
| 718 | + base = "default" |
| 719 | + extra_style = neutral_theme.extra_style |
| 720 | + if self.shell.get_spyder_theme() == "dark": |
| 721 | + base = "monokai" |
| 722 | + extra_style = linux_theme.extra_style |
| 723 | + |
| 724 | + extra_style.update(create_pygments_dict(syntax_style)) |
| 725 | + theme = Theme("spyder_theme", base, extra_style) |
| 726 | + IPython.utils.PyColorize.theme_table["spyder_theme"] = theme |
| 727 | + self.shell.run_line_magic("colors", "spyder_theme") |
| 728 | + else: |
| 729 | + # Use `tb_highlight_style` class attribute to set the style ( |
| 730 | + # IPython 8.x) |
| 731 | + import IPython.core.ultratb |
| 732 | + from IPython.core.ultratb import VerboseTB |
710 | 733 |
|
711 | | - IPython.core.ultratb.get_style_by_name = create_style_class |
| 734 | + IPython.core.ultratb.get_style_by_name = create_style_class |
712 | 735 |
|
713 | | - if getattr(VerboseTB, 'tb_highlight_style', None) is not None: |
714 | | - VerboseTB.tb_highlight_style = syntax_style |
715 | | - elif getattr(VerboseTB, '_tb_highlight_style', None) is not None: |
716 | | - VerboseTB._tb_highlight_style = syntax_style |
| 736 | + if getattr(VerboseTB, "tb_highlight_style", None) is not None: |
| 737 | + VerboseTB.tb_highlight_style = syntax_style |
| 738 | + elif getattr(VerboseTB, "_tb_highlight_style", None) is not None: |
| 739 | + VerboseTB._tb_highlight_style = syntax_style |
717 | 740 |
|
718 | 741 | def get_cwd(self): |
719 | 742 | """Get current working directory.""" |
|
0 commit comments