txl-kernel 0.2.14__tar.gz → 0.3.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {txl_kernel-0.2.14 → txl_kernel-0.3.4}/PKG-INFO +5 -5
- txl_kernel-0.3.4/pyproject.toml +20 -0
- {txl_kernel-0.2.14 → txl_kernel-0.3.4}/txl_kernel/driver.py +48 -63
- txl_kernel-0.2.14/pyproject.toml +0 -33
- {txl_kernel-0.2.14 → txl_kernel-0.3.4}/.gitignore +0 -0
- {txl_kernel-0.2.14 → txl_kernel-0.3.4}/LICENSE.txt +0 -0
- {txl_kernel-0.2.14 → txl_kernel-0.3.4}/README.md +0 -0
- {txl_kernel-0.2.14 → txl_kernel-0.3.4}/txl_kernel/__init__.py +0 -0
- {txl_kernel-0.2.14 → txl_kernel-0.3.4}/txl_kernel/message.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: txl_kernel
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.4
|
|
4
4
|
Summary: TXL plugin for a kernel driver
|
|
5
5
|
Project-URL: Source, https://github.com/davidbrochart/jpterm/plugins/kernel
|
|
6
6
|
Author-email: David Brochart <david.brochart@gmail.com>
|
|
@@ -11,13 +11,13 @@ Classifier: Programming Language :: Python
|
|
|
11
11
|
Classifier: Programming Language :: Python :: 3.10
|
|
12
12
|
Classifier: Programming Language :: Python :: 3.11
|
|
13
13
|
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
15
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
15
16
|
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
16
17
|
Requires-Python: >=3.10
|
|
17
|
-
Requires-Dist:
|
|
18
|
-
Requires-Dist: pycrdt<0.9.0,>=0.8.11
|
|
18
|
+
Requires-Dist: pycrdt<0.13.0,>=0.10.9
|
|
19
19
|
Requires-Dist: python-dateutil>=2.8.2
|
|
20
|
-
Requires-Dist: txl
|
|
20
|
+
Requires-Dist: txl==0.3.1
|
|
21
21
|
Description-Content-Type: text/markdown
|
|
22
22
|
|
|
23
23
|
# TXL plugin for a kernel driver
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = [ "hatchling",]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "txl_kernel"
|
|
7
|
+
version = "0.3.4"
|
|
8
|
+
description = "TXL plugin for a kernel driver"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
keywords = []
|
|
13
|
+
classifiers = [ "Development Status :: 4 - Beta", "Programming Language :: Python", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy",]
|
|
14
|
+
dependencies = [ "txl ==0.3.1", "python-dateutil >=2.8.2", "pycrdt >=0.10.9,<0.13.0",]
|
|
15
|
+
[[project.authors]]
|
|
16
|
+
name = "David Brochart"
|
|
17
|
+
email = "david.brochart@gmail.com"
|
|
18
|
+
|
|
19
|
+
[project.urls]
|
|
20
|
+
Source = "https://github.com/davidbrochart/jpterm/plugins/kernel"
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import asyncio
|
|
2
1
|
import time
|
|
3
2
|
from typing import Dict
|
|
4
3
|
|
|
5
|
-
from
|
|
4
|
+
from anyio import move_on_after
|
|
5
|
+
from anyioutils import Event, Queue, create_task
|
|
6
|
+
from fps import Signal
|
|
6
7
|
from pycrdt import Array, Map
|
|
7
8
|
|
|
8
9
|
from .message import create_message
|
|
@@ -13,11 +14,12 @@ def deadline_to_timeout(deadline: float) -> float:
|
|
|
13
14
|
|
|
14
15
|
|
|
15
16
|
class Comm:
|
|
16
|
-
def __init__(self, comm_id: str, shell_channel, session_id: str, send_message):
|
|
17
|
+
def __init__(self, comm_id: str, shell_channel, session_id: str, send_message, task_group):
|
|
17
18
|
self.comm_id = comm_id
|
|
18
19
|
self.shell_channel = shell_channel
|
|
19
20
|
self.session_id = session_id
|
|
20
21
|
self.send_message = send_message
|
|
22
|
+
self.task_group = task_group
|
|
21
23
|
self.msg_cnt = 0
|
|
22
24
|
|
|
23
25
|
def send(self, buffers):
|
|
@@ -29,24 +31,20 @@ class Comm:
|
|
|
29
31
|
buffers=buffers,
|
|
30
32
|
)
|
|
31
33
|
self.msg_cnt += 1
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
class BusyEvent(Event):
|
|
36
|
-
def __init__(self, source, topic, busy: bool):
|
|
37
|
-
super().__init__(source, topic)
|
|
38
|
-
self.busy = busy
|
|
34
|
+
create_task(
|
|
35
|
+
self.send_message(msg, self.shell_channel, change_date_to_str=True), self.task_group
|
|
36
|
+
)
|
|
39
37
|
|
|
40
38
|
|
|
41
39
|
class KernelMixin:
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
def __init__(self, task_group):
|
|
41
|
+
self.task_group = task_group
|
|
42
|
+
self.busy = Signal[bool]()
|
|
45
43
|
self.msg_cnt = 0
|
|
46
|
-
self.execute_requests: Dict[str, Dict[str,
|
|
47
|
-
self.recv_queue =
|
|
48
|
-
self.started =
|
|
49
|
-
|
|
44
|
+
self.execute_requests: Dict[str, Dict[str, Queue]] = {}
|
|
45
|
+
self.recv_queue = Queue()
|
|
46
|
+
self.started = Event()
|
|
47
|
+
create_task(self.recv(), task_group)
|
|
50
48
|
|
|
51
49
|
def create_message(self, *args, **kwargs):
|
|
52
50
|
return create_message(*args, **kwargs)
|
|
@@ -64,23 +62,19 @@ class KernelMixin:
|
|
|
64
62
|
await self.send_message(msg, self.shell_channel, change_date_to_str=True)
|
|
65
63
|
msg_id = msg["header"]["msg_id"]
|
|
66
64
|
self.execute_requests[msg_id] = {
|
|
67
|
-
"iopub":
|
|
68
|
-
"shell":
|
|
65
|
+
"iopub": Queue(),
|
|
66
|
+
"shell": Queue(),
|
|
69
67
|
}
|
|
70
|
-
|
|
71
|
-
msg = await
|
|
72
|
-
|
|
73
|
-
)
|
|
74
|
-
except asyncio.TimeoutError:
|
|
68
|
+
with move_on_after(new_timeout) as scope:
|
|
69
|
+
msg = await self.execute_requests[msg_id]["shell"].get()
|
|
70
|
+
if scope.cancelled_caught:
|
|
75
71
|
del self.execute_requests[msg_id]
|
|
76
72
|
error_message = f"Kernel didn't respond in {timeout} seconds"
|
|
77
73
|
raise RuntimeError(error_message)
|
|
78
74
|
if msg["header"]["msg_type"] == "kernel_info_reply":
|
|
79
|
-
|
|
80
|
-
msg = await
|
|
81
|
-
|
|
82
|
-
pass
|
|
83
|
-
else:
|
|
75
|
+
with move_on_after(0.2) as scope:
|
|
76
|
+
msg = await self.execute_requests[msg_id]["iopub"].get()
|
|
77
|
+
if not scope.cancelled_caught:
|
|
84
78
|
break
|
|
85
79
|
del self.execute_requests[msg_id]
|
|
86
80
|
new_timeout = deadline_to_timeout(deadline)
|
|
@@ -93,7 +87,13 @@ class KernelMixin:
|
|
|
93
87
|
if msg_type == "comm_open":
|
|
94
88
|
for comm_handler in self.comm_handlers:
|
|
95
89
|
comm_id = msg["content"]["comm_id"]
|
|
96
|
-
comm = Comm(
|
|
90
|
+
comm = Comm(
|
|
91
|
+
comm_id,
|
|
92
|
+
self.shell_channel,
|
|
93
|
+
self.session_id,
|
|
94
|
+
self.send_message,
|
|
95
|
+
self.task_group,
|
|
96
|
+
)
|
|
97
97
|
comm_handler.comm_open(msg, comm)
|
|
98
98
|
elif msg_type == "comm_msg":
|
|
99
99
|
for comm_handler in self.comm_handlers:
|
|
@@ -101,9 +101,9 @@ class KernelMixin:
|
|
|
101
101
|
elif msg_type == "status":
|
|
102
102
|
execution_state = msg["content"]["execution_state"]
|
|
103
103
|
if execution_state == "idle":
|
|
104
|
-
self.busy.
|
|
104
|
+
await self.busy.emit(False)
|
|
105
105
|
elif execution_state == "busy":
|
|
106
|
-
self.busy.
|
|
106
|
+
await self.busy.emit(True)
|
|
107
107
|
msg_id = msg["parent_header"].get("msg_id")
|
|
108
108
|
if msg_id in self.execute_requests:
|
|
109
109
|
# msg["header"] = str_to_date(msg["header"])
|
|
@@ -136,19 +136,16 @@ class KernelMixin:
|
|
|
136
136
|
msg_id = msg["header"]["msg_id"]
|
|
137
137
|
self.msg_cnt += 1
|
|
138
138
|
self.execute_requests[msg_id] = {
|
|
139
|
-
"iopub":
|
|
140
|
-
"shell":
|
|
139
|
+
"iopub": Queue(),
|
|
140
|
+
"shell": Queue(),
|
|
141
141
|
}
|
|
142
142
|
await self.send_message(msg, self.shell_channel, change_date_to_str=True)
|
|
143
143
|
if wait_for_executed:
|
|
144
144
|
deadline = time.monotonic() + timeout
|
|
145
145
|
while True:
|
|
146
|
-
|
|
147
|
-
msg = await
|
|
148
|
-
|
|
149
|
-
deadline_to_timeout(deadline),
|
|
150
|
-
)
|
|
151
|
-
except asyncio.TimeoutError:
|
|
146
|
+
with move_on_after(deadline_to_timeout(deadline)) as scope:
|
|
147
|
+
msg = await self.execute_requests[msg_id]["iopub"].get()
|
|
148
|
+
if scope.cancelled_caught:
|
|
152
149
|
del self.execute_requests[msg_id]
|
|
153
150
|
error_message = f"Kernel didn't respond in {timeout} seconds"
|
|
154
151
|
raise RuntimeError(error_message)
|
|
@@ -158,12 +155,9 @@ class KernelMixin:
|
|
|
158
155
|
and msg["content"]["execution_state"] == "idle")
|
|
159
156
|
):
|
|
160
157
|
break
|
|
161
|
-
|
|
162
|
-
msg = await
|
|
163
|
-
|
|
164
|
-
deadline_to_timeout(deadline),
|
|
165
|
-
)
|
|
166
|
-
except asyncio.TimeoutError:
|
|
158
|
+
with move_on_after(deadline_to_timeout(deadline)) as scope:
|
|
159
|
+
msg = await self.execute_requests[msg_id]["shell"].get()
|
|
160
|
+
if scope.cancelled_caught:
|
|
167
161
|
del self.execute_requests[msg_id]
|
|
168
162
|
error_message = f"Kernel didn't respond in {timeout} seconds"
|
|
169
163
|
raise RuntimeError(error_message)
|
|
@@ -175,27 +169,18 @@ class KernelMixin:
|
|
|
175
169
|
content = msg["content"]
|
|
176
170
|
if msg_type == "stream":
|
|
177
171
|
with outputs.doc.transaction():
|
|
178
|
-
# TODO: uncomment when changes are made in jupyter-ydoc
|
|
179
172
|
if (not outputs) or (outputs[-1]["name"] != content["name"]): # type: ignore
|
|
180
173
|
outputs.append(
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
{
|
|
189
|
-
"name": content["name"],
|
|
190
|
-
"output_type": msg_type,
|
|
191
|
-
"text": [content["text"]],
|
|
192
|
-
}
|
|
174
|
+
Map(
|
|
175
|
+
{
|
|
176
|
+
"name": content["name"],
|
|
177
|
+
"output_type": msg_type,
|
|
178
|
+
"text": Array([content["text"]]),
|
|
179
|
+
}
|
|
180
|
+
)
|
|
193
181
|
)
|
|
194
182
|
else:
|
|
195
|
-
|
|
196
|
-
last_output = outputs[-1]
|
|
197
|
-
last_output["text"].append(content["text"]) # type: ignore
|
|
198
|
-
outputs[-1] = last_output
|
|
183
|
+
outputs[-1]["text"].append(content["text"]) # type: ignore
|
|
199
184
|
elif msg_type in ("display_data", "execute_result"):
|
|
200
185
|
outputs.append(
|
|
201
186
|
{
|
txl_kernel-0.2.14/pyproject.toml
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
[build-system]
|
|
2
|
-
requires = ["hatchling"]
|
|
3
|
-
build-backend = "hatchling.build"
|
|
4
|
-
|
|
5
|
-
[project]
|
|
6
|
-
name = "txl_kernel"
|
|
7
|
-
version = "0.2.14"
|
|
8
|
-
description = "TXL plugin for a kernel driver"
|
|
9
|
-
readme = "README.md"
|
|
10
|
-
requires-python = ">=3.10"
|
|
11
|
-
license = "MIT"
|
|
12
|
-
keywords = []
|
|
13
|
-
authors = [
|
|
14
|
-
{ name = "David Brochart", email = "david.brochart@gmail.com" },
|
|
15
|
-
]
|
|
16
|
-
classifiers = [
|
|
17
|
-
"Development Status :: 4 - Beta",
|
|
18
|
-
"Programming Language :: Python",
|
|
19
|
-
"Programming Language :: Python :: 3.10",
|
|
20
|
-
"Programming Language :: Python :: 3.11",
|
|
21
|
-
"Programming Language :: Python :: 3.12",
|
|
22
|
-
"Programming Language :: Python :: Implementation :: CPython",
|
|
23
|
-
"Programming Language :: Python :: Implementation :: PyPy",
|
|
24
|
-
]
|
|
25
|
-
dependencies = [
|
|
26
|
-
"txl >=0.2.18,<0.3.0",
|
|
27
|
-
"asphalt >=4.0.0,<5.0.0",
|
|
28
|
-
"python-dateutil >=2.8.2",
|
|
29
|
-
"pycrdt >=0.8.11,<0.9.0",
|
|
30
|
-
]
|
|
31
|
-
|
|
32
|
-
[project.urls]
|
|
33
|
-
Source = "https://github.com/davidbrochart/jpterm/plugins/kernel"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|