txl_kernel 0.2.12__tar.gz → 0.3.1__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.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.4
2
2
  Name: txl_kernel
3
- Version: 0.2.12
3
+ Version: 0.3.1
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: asphalt
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.0,>=0.2.18
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.1"
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.2.18,<0.3.0", "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"
File without changes
@@ -1,8 +1,9 @@
1
- import asyncio
2
1
  import time
3
2
  from typing import Dict
4
3
 
5
- from asphalt.core import Event, Signal
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,18 @@ class Comm:
29
31
  buffers=buffers,
30
32
  )
31
33
  self.msg_cnt += 1
32
- asyncio.create_task(self.send_message(msg, self.shell_channel, change_date_to_str=True))
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(self.send_message(msg, self.shell_channel, change_date_to_str=True), self.task_group)
39
35
 
40
36
 
41
37
  class KernelMixin:
42
- busy = Signal(BusyEvent)
43
-
44
- def __init__(self):
38
+ def __init__(self, task_group):
39
+ self.task_group = task_group
40
+ self.busy = Signal[bool]()
45
41
  self.msg_cnt = 0
46
- self.execute_requests: Dict[str, Dict[str, asyncio.Queue]] = {}
47
- self.recv_queue = asyncio.Queue()
48
- self.started = asyncio.Event()
49
- asyncio.create_task(self.recv())
42
+ self.execute_requests: Dict[str, Dict[str, Queue]] = {}
43
+ self.recv_queue = Queue()
44
+ self.started = Event()
45
+ create_task(self.recv(), task_group)
50
46
 
51
47
  def create_message(self, *args, **kwargs):
52
48
  return create_message(*args, **kwargs)
@@ -64,23 +60,19 @@ class KernelMixin:
64
60
  await self.send_message(msg, self.shell_channel, change_date_to_str=True)
65
61
  msg_id = msg["header"]["msg_id"]
66
62
  self.execute_requests[msg_id] = {
67
- "iopub": asyncio.Queue(),
68
- "shell": asyncio.Queue(),
63
+ "iopub": Queue(),
64
+ "shell": Queue(),
69
65
  }
70
- try:
71
- msg = await asyncio.wait_for(
72
- self.execute_requests[msg_id]["shell"].get(), new_timeout
73
- )
74
- except asyncio.TimeoutError:
66
+ with move_on_after(new_timeout) as scope:
67
+ msg = await self.execute_requests[msg_id]["shell"].get()
68
+ if scope.cancelled_caught:
75
69
  del self.execute_requests[msg_id]
76
70
  error_message = f"Kernel didn't respond in {timeout} seconds"
77
71
  raise RuntimeError(error_message)
78
72
  if msg["header"]["msg_type"] == "kernel_info_reply":
79
- try:
80
- msg = await asyncio.wait_for(self.execute_requests[msg_id]["iopub"].get(), 0.2)
81
- except asyncio.TimeoutError:
82
- pass
83
- else:
73
+ with move_on_after(0.2) as scope:
74
+ msg = await self.execute_requests[msg_id]["iopub"].get()
75
+ if not scope.cancelled_caught:
84
76
  break
85
77
  del self.execute_requests[msg_id]
86
78
  new_timeout = deadline_to_timeout(deadline)
@@ -93,7 +85,7 @@ class KernelMixin:
93
85
  if msg_type == "comm_open":
94
86
  for comm_handler in self.comm_handlers:
95
87
  comm_id = msg["content"]["comm_id"]
96
- comm = Comm(comm_id, self.shell_channel, self.session_id, self.send_message)
88
+ comm = Comm(comm_id, self.shell_channel, self.session_id, self.send_message, self.task_group)
97
89
  comm_handler.comm_open(msg, comm)
98
90
  elif msg_type == "comm_msg":
99
91
  for comm_handler in self.comm_handlers:
@@ -101,9 +93,9 @@ class KernelMixin:
101
93
  elif msg_type == "status":
102
94
  execution_state = msg["content"]["execution_state"]
103
95
  if execution_state == "idle":
104
- self.busy.dispatch(False)
96
+ await self.busy.emit(False)
105
97
  elif execution_state == "busy":
106
- self.busy.dispatch(True)
98
+ await self.busy.emit(True)
107
99
  msg_id = msg["parent_header"].get("msg_id")
108
100
  if msg_id in self.execute_requests:
109
101
  # msg["header"] = str_to_date(msg["header"])
@@ -121,6 +113,7 @@ class KernelMixin:
121
113
  if ycell["cell_type"] != "code":
122
114
  return
123
115
  ycell["outputs"].clear()
116
+ ycell["execution_count"] = None
124
117
  code = str(ycell["source"])
125
118
  content = {"code": code, "silent": False}
126
119
  msg = create_message(
@@ -135,19 +128,16 @@ class KernelMixin:
135
128
  msg_id = msg["header"]["msg_id"]
136
129
  self.msg_cnt += 1
137
130
  self.execute_requests[msg_id] = {
138
- "iopub": asyncio.Queue(),
139
- "shell": asyncio.Queue(),
131
+ "iopub": Queue(),
132
+ "shell": Queue(),
140
133
  }
141
134
  await self.send_message(msg, self.shell_channel, change_date_to_str=True)
142
135
  if wait_for_executed:
143
136
  deadline = time.monotonic() + timeout
144
137
  while True:
145
- try:
146
- msg = await asyncio.wait_for(
147
- self.execute_requests[msg_id]["iopub"].get(),
148
- deadline_to_timeout(deadline),
149
- )
150
- except asyncio.TimeoutError:
138
+ with move_on_after(deadline_to_timeout(deadline)) as scope:
139
+ msg = await self.execute_requests[msg_id]["iopub"].get()
140
+ if scope.cancelled_caught:
151
141
  del self.execute_requests[msg_id]
152
142
  error_message = f"Kernel didn't respond in {timeout} seconds"
153
143
  raise RuntimeError(error_message)
@@ -157,12 +147,9 @@ class KernelMixin:
157
147
  and msg["content"]["execution_state"] == "idle")
158
148
  ):
159
149
  break
160
- try:
161
- msg = await asyncio.wait_for(
162
- self.execute_requests[msg_id]["shell"].get(),
163
- deadline_to_timeout(deadline),
164
- )
165
- except asyncio.TimeoutError:
150
+ with move_on_after(deadline_to_timeout(deadline)) as scope:
151
+ msg = await self.execute_requests[msg_id]["shell"].get()
152
+ if scope.cancelled_caught:
166
153
  del self.execute_requests[msg_id]
167
154
  error_message = f"Kernel didn't respond in {timeout} seconds"
168
155
  raise RuntimeError(error_message)
@@ -174,27 +161,18 @@ class KernelMixin:
174
161
  content = msg["content"]
175
162
  if msg_type == "stream":
176
163
  with outputs.doc.transaction():
177
- # TODO: uncomment when changes are made in jupyter-ydoc
178
164
  if (not outputs) or (outputs[-1]["name"] != content["name"]): # type: ignore
179
165
  outputs.append(
180
- #Map(
181
- # {
182
- # "name": content["name"],
183
- # "output_type": msg_type,
184
- # "text": Array([content["text"]]),
185
- # }
186
- #)
187
- {
188
- "name": content["name"],
189
- "output_type": msg_type,
190
- "text": [content["text"]],
191
- }
166
+ Map(
167
+ {
168
+ "name": content["name"],
169
+ "output_type": msg_type,
170
+ "text": Array([content["text"]]),
171
+ }
172
+ )
192
173
  )
193
174
  else:
194
- #outputs[-1]["text"].append(content["text"]) # type: ignore
195
- last_output = outputs[-1]
196
- last_output["text"].append(content["text"]) # type: ignore
197
- outputs[-1] = last_output
175
+ outputs[-1]["text"].append(content["text"]) # type: ignore
198
176
  elif msg_type in ("display_data", "execute_result"):
199
177
  outputs.append(
200
178
  {
@@ -1,36 +0,0 @@
1
- [build-system]
2
- requires = ["hatchling"]
3
- build-backend = "hatchling.build"
4
-
5
- [project]
6
- name = "txl_kernel"
7
- description = "TXL plugin for a kernel driver"
8
- readme = "README.md"
9
- requires-python = ">=3.10"
10
- license = "MIT"
11
- keywords = []
12
- authors = [
13
- { name = "David Brochart", email = "david.brochart@gmail.com" },
14
- ]
15
- classifiers = [
16
- "Development Status :: 4 - Beta",
17
- "Programming Language :: Python",
18
- "Programming Language :: Python :: 3.10",
19
- "Programming Language :: Python :: 3.11",
20
- "Programming Language :: Python :: 3.12",
21
- "Programming Language :: Python :: Implementation :: CPython",
22
- "Programming Language :: Python :: Implementation :: PyPy",
23
- ]
24
- dependencies = [
25
- "txl",
26
- "asphalt",
27
- "python-dateutil >=2.8.2",
28
- "pycrdt >=0.8.11,<0.9.0",
29
- ]
30
- dynamic = ["version"]
31
-
32
- [project.urls]
33
- Source = "https://github.com/davidbrochart/jpterm/plugins/kernel"
34
-
35
- [tool.hatch.version]
36
- path = "txl_kernel/__init__.py"
@@ -1 +0,0 @@
1
- __version__ = "0.2.12"
File without changes
File without changes
File without changes