37
37
...
38
38
39
39
40
- # FIXME should we use caching to retrieve faster at least the document
40
+ # FIXME should we use caching to retrieve faster at least the document.
41
41
async def _get_ycell (
42
42
ydoc : jupyter_server_ydoc .app .YDocExtension | None ,
43
43
metadata : dict | None ,
@@ -54,26 +54,20 @@ async def _get_ycell(
54
54
msg = "jupyter-collaboration extension is not installed on the server. Outputs won't be written within the document." # noqa: E501
55
55
get_logger ().warning (msg )
56
56
return None
57
-
58
57
document_id = metadata .get ("document_id" )
59
58
cell_id = metadata .get ("cell_id" )
60
-
61
59
if document_id is None or cell_id is None :
62
60
msg = (
63
61
"document_id and cell_id not defined. The outputs won't be written within the document."
64
62
)
65
63
get_logger ().debug (msg )
66
64
return None
67
-
68
65
notebook : YNotebook | None = await ydoc .get_document (room_id = document_id , copy = False )
69
-
70
66
if notebook is None :
71
67
msg = f"Document with ID { document_id } not found."
72
68
get_logger ().warning (msg )
73
69
return None
74
-
75
70
ycells = filter (lambda c : c ["id" ] == cell_id , notebook .ycells )
76
-
77
71
ycell = next (ycells , None )
78
72
if ycell is None :
79
73
msg = f"Cell with ID { cell_id } not found in document { document_id } ."
@@ -83,7 +77,6 @@ async def _get_ycell(
83
77
# Check if there is more than one cell
84
78
if next (ycells , None ) is not None :
85
79
get_logger ().warning ("Multiple cells have the same ID '%s'." , cell_id )
86
-
87
80
if ycell ["cell_type" ] != "code" :
88
81
msg = f"Cell with ID { cell_id } of document { document_id } is not of type code."
89
82
get_logger ().error (msg )
@@ -106,17 +99,14 @@ def _output_hook(outputs: list[NotebookNode], ycell: y.Map | None, msg: dict) ->
106
99
# FIXME support for version
107
100
output = nbformat .v4 .output_from_msg (msg )
108
101
outputs .append (output )
109
-
110
102
if ycell is not None :
111
103
cell_outputs = ycell ["outputs" ]
112
104
if msg_type == "stream" :
113
105
with cell_outputs .doc .transaction ():
114
106
text = output ["text" ]
115
-
116
107
# FIXME Logic is quite complex at https://github.com/jupyterlab/jupyterlab/blob/7ae2d436fc410b0cff51042a3350ba71f54f4445/packages/outputarea/src/model.ts#L518
117
108
if text .endswith ((os .linesep , "\n " )):
118
109
text = text [:- 1 ]
119
-
120
110
if (not cell_outputs ) or (cell_outputs [- 1 ]["name" ] != output ["name" ]):
121
111
output ["text" ] = [text ]
122
112
cell_outputs .append (output )
@@ -127,14 +117,11 @@ def _output_hook(outputs: list[NotebookNode], ycell: y.Map | None, msg: dict) ->
127
117
else :
128
118
with cell_outputs .doc .transaction ():
129
119
cell_outputs .append (output )
130
-
131
120
elif msg_type == "clear_output" :
132
121
# FIXME msg.content.wait - if true should clear at the next message
133
122
outputs .clear ()
134
-
135
123
if ycell is not None :
136
124
del ycell ["outputs" ][:]
137
-
138
125
elif msg_type == "update_display_data" :
139
126
# FIXME
140
127
...
@@ -157,7 +144,6 @@ def _stdin_hook(kernel_id: str, request_id: str, pending_input: PendingInput, ms
157
144
get_logger ().error (
158
145
f"Execution request { kernel_id } received a input request while waiting for an input.\n { msg } " # noqa: E501
159
146
)
160
-
161
147
header = msg ["header" ].copy ()
162
148
header ["date" ] = header ["date" ].isoformat ()
163
149
pending_input .request_id = request_id
@@ -222,7 +208,6 @@ async def _execute_snippet(
222
208
}
223
209
)
224
210
outputs = []
225
-
226
211
# FIXME we don't check if the session is consistent (aka the kernel is linked to the document)
227
212
# - should we?
228
213
reply = await ensure_async (
@@ -233,9 +218,7 @@ async def _execute_snippet(
233
218
stdin_hook = stdin_hook if client .allow_stdin else None ,
234
219
)
235
220
)
236
-
237
221
reply_content = reply ["content" ]
238
-
239
222
if ycell is not None :
240
223
execution_end_time = datetime .now (timezone .utc ).isoformat ()[:- 6 ]
241
224
with ycell .doc .transaction ():
@@ -289,7 +272,6 @@ async def kernel_worker(
289
272
results [uid ] = await _execute_snippet (
290
273
client , ydoc , snippet , metadata , partial (_stdin_hook , kernel_id , uid , pending_input )
291
274
)
292
-
293
275
queue .task_done ()
294
276
get_logger ().debug (f"Execution request { uid } processed for kernel { kernel_id } ." )
295
277
except (asyncio .CancelledError , KeyboardInterrupt , RuntimeError ) as e :
@@ -307,6 +289,5 @@ async def kernel_worker(
307
289
)
308
290
if not queue .empty ():
309
291
queue .task_done ()
310
-
311
292
if to_raise is not None :
312
293
raise to_raise
0 commit comments