Skip to content

Commit ce6a3f7

Browse files
committed
Merge branch 'master' into add-profile-magics
2 parents 2b74b3f + 453262e commit ce6a3f7

File tree

8 files changed

+138
-134
lines changed

8 files changed

+138
-134
lines changed

pyproject.toml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
[build-system]
2+
requires = ["setuptools"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[tool.setuptools.dynamic]
6+
version = {attr = "spyder_kernels._version.__version__"}
7+
8+
[tool.setuptools.packages.find]
9+
exclude = ["docs", "*tests"]
10+
11+
[project]
12+
name = "spyder-kernels"
13+
dynamic = ["version"]
14+
description = "Jupyter kernels for Spyder's console"
15+
keywords = ["spyder jupyter kernel ipython console"]
16+
readme = "README.md"
17+
authors = [
18+
{name = "Spyder Development Team", email = "[email protected]"},
19+
]
20+
classifiers = [
21+
"Development Status :: 5 - Production/Stable",
22+
"Framework :: IPython",
23+
"Framework :: Jupyter",
24+
"Intended Audience :: Developers",
25+
"Operating System :: OS Independent",
26+
"Programming Language :: Python :: 3",
27+
"Programming Language :: Python :: 3.10",
28+
"Programming Language :: Python :: 3.11",
29+
"Programming Language :: Python :: 3.12",
30+
"Programming Language :: Python :: 3.13",
31+
"Programming Language :: Python :: 3.9",
32+
"Topic :: Software Development :: Interpreters",
33+
]
34+
requires-python = ">=3.9"
35+
dependencies = [
36+
"cloudpickle",
37+
"ipykernel>=6.29.3,<7",
38+
"ipython>=8.13.0,<10,!=8.17.1,!=9.1.0,!=9.2.0,!=9.3.0,!=9.4.0",
39+
"jupyter-client>=7.4.9,<9",
40+
"packaging",
41+
"pyxdg>=0.26;platform_system=='Linux'",
42+
"pyzmq>=24.0.0",
43+
# We need at least this version of traitlets to fix an error when setting
44+
# the Matplotlib inline backend formats.
45+
# Fixes spyder-ide/spyder#24390
46+
"traitlets>=5.14.3",
47+
"wurlitzer>=1.0.3;platform_system!='Windows'",
48+
]
49+
license = "MIT"
50+
51+
[project.urls]
52+
Homepage = "https://github.com/spyder-ide/spyder-kernels"
53+
54+
[project.optional-dependencies]
55+
test = [
56+
"anyio",
57+
"cython",
58+
"dask[distributed]",
59+
"django",
60+
"flaky",
61+
"h5py",
62+
"matplotlib",
63+
"mock",
64+
"numpy",
65+
"pandas",
66+
"pillow",
67+
"polars",
68+
"pyarrow",
69+
"pydicom",
70+
"pytest",
71+
"pytest-cov",
72+
"scipy",
73+
"xarray",
74+
]

requirements/posix.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cloudpickle
22
ipykernel>=6.29.3,<7
3-
ipython>=8.12.2,<9
3+
ipython>=8.13.0,<10,!=8.17.1,!=9.1.0,!=9.2.0,!=9.3.0,!=9.4.0
44
jupyter_client>=7.4.9,<9
55
pyzmq>=24.0.0
66
pyxdg>=0.26

requirements/windows.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cloudpickle
22
ipykernel>=6.29.3,<7
3-
ipython>=8.12.2,<9
3+
ipython>=8.13.0,<10,!=8.17.1,!=9.1.0,!=9.2.0,!=9.3.0,!=9.4.0
44
jupyter_client>=7.4.9,<9
55
pyzmq>=24.0.0
66
traitlets>=5.14.3

setup.py

Lines changed: 0 additions & 106 deletions
This file was deleted.

spyder_kernels/console/kernel.py

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from ipykernel.ipkernel import IPythonKernel
2828
from ipykernel import get_connection_info
2929
from IPython.core import release as ipython_release
30+
from packaging.version import parse as parse_version
3031
from traitlets.config.loader import Config, LazyConfigValue
3132
import zmq
3233
from zmq.utils.garbage import gc
@@ -49,7 +50,7 @@
4950
from spyder_kernels.utils.mpl import automatic_backend, MPL_BACKENDS_TO_SPYDER
5051
from spyder_kernels.utils.nsview import (
5152
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
5354
from spyder_kernels.console.shell import SpyderShell
5455
from spyder_kernels.comms.utils import WriteContext
5556

@@ -705,15 +706,37 @@ def set_traceback_highlighting(self, color_scheme):
705706

706707
def set_traceback_syntax_highlighting(self, syntax_style):
707708
"""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
710733

711-
IPython.core.ultratb.get_style_by_name = create_style_class
734+
IPython.core.ultratb.get_style_by_name = create_style_class
712735

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
717740

718741
def get_cwd(self):
719742
"""Get current working directory."""

spyder_kernels/console/shell.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424

2525
# Third-party imports
2626
from ipykernel.zmqshell import ZMQInteractiveShell
27+
from IPython.core import release as ipython_release
28+
from packaging.version import parse as parse_version
29+
2730

2831
# Local imports
2932
from spyder_kernels.customize.namespace_manager import NamespaceManager
@@ -117,9 +120,11 @@ def _showtraceback(self, etype, evalue, stb):
117120
for line in stb:
118121
if (
119122
# Verbose mode
120-
re.match(r"File (.*)", line)
123+
re.match(r"File (.*)", line) # IPython 8.x
124+
or re.match(r"\x1b(.*)File (.*)", line) # IPython 9.x
121125
# Plain mode
122-
or re.match(r"\x1b\[(.*) File (.*)", line)
126+
or re.match(r"\x1b\[(.*) File (.*)", line) # IPython 8.x
127+
or re.match(r" File (.*)", line) # IPython 9.x
123128
) and (
124129
# The file line should not contain a location where
125130
# Spyder-kernels is installed
@@ -139,11 +144,11 @@ def _showtraceback(self, etype, evalue, stb):
139144
def set_spyder_theme(self, theme):
140145
"""Set the theme for the console."""
141146
self._spyder_theme = theme
142-
if theme == "dark":
143-
# Needed to change the colors of tracebacks
144-
self.run_line_magic("colors", "linux")
145-
elif theme == "light":
146-
self.run_line_magic("colors", "lightbg")
147+
148+
# Call `%colors` following theme for IPython 8.x tracebacks
149+
if parse_version(ipython_release.version) < parse_version("9.0"):
150+
colors = "linux" if theme == "dark" else "lightbg"
151+
self.run_line_magic("colors", colors)
147152

148153
def get_spyder_theme(self):
149154
"""Get the theme for the console."""

spyder_kernels/console/start.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
import sys
1717
import site
1818

19+
# Third-party imports
20+
from IPython.core import release as ipython_release
21+
from packaging.version import parse as parse_version
22+
23+
1924
# Remove current directory from sys.path to prevent kernel crashes when people
2025
# name Python files or modules with the same name as standard library modules.
2126
# See spyder-ide/spyder#8007
@@ -101,6 +106,10 @@ def kernel_config():
101106
# To handle the banner by ourselves
102107
spy_cfg.ZMQInteractiveShell.banner1 = ''
103108

109+
# To disable tips (for the moment) that are only available in IPython 9.0+
110+
if parse_version(ipython_release.version) >= parse_version("9.0"):
111+
spy_cfg.ZMQInteractiveShell.enable_tip = False
112+
104113
# Greedy completer
105114
greedy_o = os.environ.get('SPY_GREEDY_O') == 'True'
106115
spy_cfg.IPCompleter.greedy = greedy_o

0 commit comments

Comments
 (0)