Skip to content

Commit 993adda

Browse files
tornariaclassabbyamp
authored andcommitted
python3-ipython_ipykernel: patch for python 3.13
1 parent 6d7244d commit 993adda

File tree

4 files changed

+299
-2
lines changed

4 files changed

+299
-2
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
Taken from https://github.com/ipython/ipykernel/pull/1248
2+
3+
From 3e7fb7c787511212ccb642004b4331a59594a329 Mon Sep 17 00:00:00 2001
4+
From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <[email protected]>
5+
Date: Mon, 10 Jun 2024 16:11:33 +0200
6+
Subject: [PATCH] Avoid a DeprecationWarning on Python 3.13+
7+
8+
...
9+
/usr/lib/python3.13/site-packages/ipykernel/jsonutil.py:29: in <module>
10+
datetime.strptime("1", "%d")
11+
/usr/lib64/python3.13/_strptime.py:573: in _strptime_datetime
12+
tt, fraction, gmtoff_fraction = _strptime(data_string, format)
13+
/usr/lib64/python3.13/_strptime.py:336: in _strptime
14+
format_regex = _TimeRE_cache.compile(format)
15+
/usr/lib64/python3.13/_strptime.py:282: in compile
16+
return re_compile(self.pattern(format), IGNORECASE)
17+
/usr/lib64/python3.13/_strptime.py:270: in pattern
18+
warnings.warn("""\
19+
E DeprecationWarning: Parsing dates involving a day of month without a year specified is ambiguious
20+
E and fails to parse leap day. The default behavior will change in Python 3.15
21+
E to either always raise an exception or to use a different default year (TBD).
22+
E To avoid trouble, add a specific year to the input & format.
23+
E See https://github.com/python/cpython/issues/70647.
24+
25+
See also https://github.com/jupyter/jupyter_client/issues/1020
26+
---
27+
ipykernel/jsonutil.py | 2 +-
28+
1 file changed, 1 insertion(+), 1 deletion(-)
29+
30+
diff --git a/ipykernel/jsonutil.py b/ipykernel/jsonutil.py
31+
index 6a463cf1..e45f06e5 100644
32+
--- a/ipykernel/jsonutil.py
33+
+++ b/ipykernel/jsonutil.py
34+
@@ -26,7 +26,7 @@
35+
36+
# holy crap, strptime is not threadsafe.
37+
# Calling it once at import seems to help.
38+
-datetime.strptime("1", "%d")
39+
+datetime.strptime("2000-01-01", "%Y-%m-%d")
40+
41+
# -----------------------------------------------------------------------------
42+
# Classes and functions
Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
Backported to 6.29.5 from https://github.com/ipython/ipykernel/pull/1277
2+
See https://github.com/ipython/ipykernel/issues/1302
3+
4+
diff --git a/docs/conf.py b/docs/conf.py
5+
index 4bb59932..38a724b5 100644
6+
--- a/docs/conf.py
7+
+++ b/docs/conf.py
8+
@@ -13,7 +13,7 @@
9+
import os
10+
import shutil
11+
from pathlib import Path
12+
-from typing import Any, Dict, List
13+
+from typing import Any
14+
15+
# If extensions (or modules to document with autodoc) are in another directory,
16+
# add these directories to sys.path here. If the directory is relative to the
17+
@@ -70,7 +70,7 @@
18+
# built documents.
19+
#
20+
21+
-version_ns: Dict[str, Any] = {}
22+
+version_ns: dict[str, Any] = {}
23+
here = Path(__file__).parent.resolve()
24+
version_py = Path(here) / os.pardir / "ipykernel" / "_version.py"
25+
with open(version_py) as f:
26+
@@ -159,7 +159,7 @@
27+
# Add any paths that contain custom static files (such as style sheets) here,
28+
# relative to this directory. They are copied after the builtin static files,
29+
# so a file named "default.css" will overwrite the builtin "default.css".
30+
-html_static_path: List[str] = []
31+
+html_static_path: list[str] = []
32+
33+
# Add any extra paths that contain custom files (such as robots.txt or
34+
# .htaccess) here, relative to this directory. These files are copied
35+
@@ -226,7 +226,7 @@
36+
37+
# -- Options for LaTeX output ---------------------------------------------
38+
39+
-latex_elements: Dict[str, object] = {}
40+
+latex_elements: dict[str, object] = {}
41+
42+
# Grouping the document tree into LaTeX files. List of tuples
43+
# (source start file, target name, title,
44+
diff --git a/ipykernel/_version.py b/ipykernel/_version.py
45+
index d9a9f534..5907d150 100644
46+
--- a/ipykernel/_version.py
47+
+++ b/ipykernel/_version.py
48+
@@ -2,7 +2,6 @@
49+
store the current version info of the server.
50+
"""
51+
import re
52+
-from typing import List
53+
54+
# Version string must appear intact for hatch versioning
55+
__version__ = "7.0.0a0"
56+
@@ -11,7 +10,7 @@
57+
pattern = r"(?P<major>\d+).(?P<minor>\d+).(?P<patch>\d+)(?P<rest>.*)"
58+
match = re.match(pattern, __version__)
59+
assert match is not None
60+
-parts: List[object] = [int(match[part]) for part in ["major", "minor", "patch"]]
61+
+parts: list[object] = [int(match[part]) for part in ["major", "minor", "patch"]]
62+
if match["rest"]:
63+
parts.append(match["rest"])
64+
version_info = tuple(parts)
65+
diff --git a/ipykernel/debugger.py b/ipykernel/debugger.py
66+
index 8680793f..780d1801 100644
67+
--- a/ipykernel/debugger.py
68+
+++ b/ipykernel/debugger.py
69+
@@ -130,7 +130,7 @@ def _reset_tcp_pos(self):
70+
71+
def _put_message(self, raw_msg):
72+
self.log.debug("QUEUE - _put_message:")
73+
- msg = t.cast(t.Dict[str, t.Any], jsonapi.loads(raw_msg))
74+
+ msg = t.cast(dict[str, t.Any], jsonapi.loads(raw_msg))
75+
if msg["type"] == "event":
76+
self.log.debug("QUEUE - received event:")
77+
self.log.debug(msg)
78+
diff --git a/ipykernel/inprocess/channels.py b/ipykernel/inprocess/channels.py
79+
index 378416dc..4c01c5bc 100644
80+
--- a/ipykernel/inprocess/channels.py
81+
+++ b/ipykernel/inprocess/channels.py
82+
@@ -3,8 +3,6 @@
83+
# Copyright (c) IPython Development Team.
84+
# Distributed under the terms of the Modified BSD License.
85+
86+
-from typing import List
87+
-
88+
from jupyter_client.channelsabc import HBChannelABC
89+
90+
# -----------------------------------------------------------------------------
91+
@@ -15,7 +13,7 @@
92+
class InProcessChannel:
93+
"""Base class for in-process channels."""
94+
95+
- proxy_methods: List[object] = []
96+
+ proxy_methods: list[object] = []
97+
98+
def __init__(self, client=None):
99+
"""Initialize the channel."""
100+
diff --git a/ipykernel/iostream.py b/ipykernel/iostream.py
101+
index beca44b1..81170b97 100644
102+
--- a/ipykernel/iostream.py
103+
+++ b/ipykernel/iostream.py
104+
@@ -15,7 +15,7 @@
105+
from collections import defaultdict, deque
106+
from io import StringIO, TextIOBase
107+
from threading import local
108+
-from typing import Any, Callable, Deque, Dict, Optional
109+
+from typing import Any, Callable, Optional
110+
111+
import zmq
112+
from jupyter_client.session import extract_header
113+
@@ -94,8 +94,8 @@ def __init__(self, socket, pipe=False):
114+
if pipe:
115+
self._setup_pipe_in()
116+
self._local = threading.local()
117+
- self._events: Deque[Callable[..., Any]] = deque()
118+
- self._event_pipes: Dict[threading.Thread, Any] = {}
119+
+ self._events: deque[Callable[..., Any]] = deque()
120+
+ self._event_pipes: dict[threading.Thread, Any] = {}
121+
self._event_pipe_gc_lock: threading.Lock = threading.Lock()
122+
self._event_pipe_gc_seconds: float = 10
123+
self._setup_event_pipe()
124+
@@ -470,7 +470,7 @@ def __init__(
125+
self.pub_thread = pub_thread
126+
self.name = name
127+
self.topic = b"stream." + name.encode()
128+
- self._parent_header: contextvars.ContextVar[Dict[str, Any]] = contextvars.ContextVar(
129+
+ self._parent_header: contextvars.ContextVar[dict[str, Any]] = contextvars.ContextVar(
130+
"parent_header"
131+
)
132+
self._parent_header.set({})
133+
diff --git a/ipykernel/ipkernel.py b/ipykernel/ipkernel.py
134+
index db83d986..48efa6cd 100644
135+
--- a/ipykernel/ipkernel.py
136+
+++ b/ipykernel/ipkernel.py
137+
@@ -1,5 +1,7 @@
138+
"""The IPython kernel implementation"""
139+
140+
+from __future__ import annotations
141+
+
142+
import asyncio
143+
import builtins
144+
import gc
145+
@@ -16,7 +18,7 @@
146+
from IPython.core import release
147+
from IPython.utils.tokenutil import line_at_cursor, token_at_cursor
148+
from jupyter_client.session import extract_header
149+
-from traitlets import Any, Bool, HasTraits, Instance, List, Type, observe, observe_compat
150+
+from traitlets import Any, Bool, HasTraits, Instance, List, Type, default, observe, observe_compat
151+
from zmq.eventloop.zmqstream import ZMQStream
152+
153+
from .comm.comm import BaseComm
154+
@@ -46,7 +48,7 @@ def _create_comm(*args, **kwargs):
155+
156+
# there can only be one comm manager in a ipykernel process
157+
_comm_lock = threading.Lock()
158+
-_comm_manager: t.Optional[CommManager] = None
159+
+_comm_manager: CommManager | None = None
160+
161+
162+
def _get_comm_manager(*args, **kwargs):
163+
@@ -84,7 +86,11 @@ def _user_module_changed(self, change):
164+
if self.shell is not None:
165+
self.shell.user_module = change["new"]
166+
167+
- user_ns = Instance(dict, args=None, allow_none=True)
168+
+ user_ns = Instance("collections.abc.Mapping", allow_none=True)
169+
+
170+
+ @default("user_ns")
171+
+ def _default_user_ns(self):
172+
+ return dict()
173+
174+
@observe("user_ns")
175+
@observe_compat
176+
@@ -353,7 +359,7 @@ async def do_execute(
177+
178+
self._forward_input(allow_stdin)
179+
180+
- reply_content: t.Dict[str, t.Any] = {}
181+
+ reply_content: dict[str, t.Any] = {}
182+
if hasattr(shell, "run_cell_async") and hasattr(shell, "should_run_async"):
183+
run_cell = shell.run_cell_async
184+
should_run_async = shell.should_run_async
185+
@@ -559,7 +565,7 @@ def do_inspect(self, code, cursor_pos, detail_level=0, omit_sections=()):
186+
"""Handle code inspection."""
187+
name = token_at_cursor(code, cursor_pos)
188+
189+
- reply_content: t.Dict[str, t.Any] = {"status": "ok"}
190+
+ reply_content: dict[str, t.Any] = {"status": "ok"}
191+
reply_content["data"] = {}
192+
reply_content["metadata"] = {}
193+
assert self.shell is not None
194+
@@ -755,7 +761,7 @@ def init_closure(self: threading.Thread, *args, **kwargs):
195+
threading.Thread.run = run_closure # type:ignore[method-assign]
196+
197+
def _clean_thread_parent_frames(
198+
- self, phase: t.Literal["start", "stop"], info: t.Dict[str, t.Any]
199+
+ self, phase: t.Literal["start", "stop"], info: dict[str, t.Any]
200+
):
201+
"""Clean parent frames of threads which are no longer running.
202+
This is meant to be invoked by garbage collector callback hook.
203+
diff --git a/ipykernel/pickleutil.py b/ipykernel/pickleutil.py
204+
index 6f156594..4ffa5262 100644
205+
--- a/ipykernel/pickleutil.py
206+
+++ b/ipykernel/pickleutil.py
207+
@@ -209,7 +209,7 @@ def __init__(self, f):
208+
"""Initialize the can"""
209+
self._check_type(f)
210+
self.code = f.__code__
211+
- self.defaults: typing.Optional[typing.List[typing.Any]]
212+
+ self.defaults: typing.Optional[list[typing.Any]]
213+
if f.__defaults__:
214+
self.defaults = [can(fd) for fd in f.__defaults__]
215+
else:
216+
@@ -475,7 +475,7 @@ def uncan_sequence(obj, g=None):
217+
if buffer is not memoryview:
218+
can_map[buffer] = CannedBuffer
219+
220+
-uncan_map: typing.Dict[type, typing.Any] = {
221+
+uncan_map: dict[type, typing.Any] = {
222+
CannedObject: lambda obj, g: obj.get_object(g),
223+
dict: uncan_dict,
224+
}
225+
diff --git a/pyproject.toml b/pyproject.toml
226+
index 1e9e543c..e1d7b1d5 100644
227+
--- a/pyproject.toml
228+
+++ b/pyproject.toml
229+
@@ -187,6 +187,9 @@ filterwarnings= [
230+
231+
# Ignore datetime warning.
232+
"ignore:datetime.datetime.utc:DeprecationWarning",
233+
+
234+
+ # ignore unclosed sqlite in traits
235+
+ "ignore:unclosed database in <sqlite3.Connection:ResourceWarning",
236+
]
237+
238+
[tool.coverage.report]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Upstream acks that ipykernel works without debugpy, but wants to keep
2+
it as a mandatory dependency, see:
3+
4+
https://github.com/ipython/ipykernel/pull/767#issuecomment-916913893
5+
6+
--- a/pyproject.toml 2020-02-01 21:00:00.000000000 -0300
7+
+++ b/pyproject.toml 2024-12-23 10:53:39.607541653 -0300
8+
@@ -20,7 +20,6 @@
9+
]
10+
requires-python = ">=3.8"
11+
dependencies = [
12+
- "debugpy>=1.6.5",
13+
"ipython>=7.23.1",
14+
"comm>=0.1.1",
15+
"traitlets>=5.4.0",

srcpkgs/python3-ipython_ipykernel/template

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
# Template file for 'python3-ipython_ipykernel'
22
pkgname=python3-ipython_ipykernel
33
version=6.29.5
4-
revision=2
4+
revision=3
55
build_style=python3-pep517
66
# run all tests available
77
make_check_target="tests"
88
hostmakedepends="hatchling python3-jupyter_client"
99
depends="python3-comm python3-ipython python3-jupyter_client
10-
python3-nest_asyncio python3-packaging python3-psutil python3-tornado"
10+
python3-jupyter_core python3-matplotlib-inline python3-nest_asyncio
11+
python3-packaging python3-psutil python3-pyzmq python3-tornado
12+
python3-traitlets"
1113
checkdepends="$depends python3-flaky python3-pytest-asyncio
1214
python3-pytest-timeout python3-trio python3-curio python3-matplotlib
1315
python3-PyQt5 python3-PyQt5-svg python3-pytest-xdist"

0 commit comments

Comments
 (0)