/
JupyterKernelCommandTests.can_connect_to_and_setup_kernel.ir.json
263 lines (263 loc) · 15 KB
/
JupyterKernelCommandTests.can_connect_to_and_setup_kernel.ir.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
[
{
"header": {
"msg_id": "f5b935d4-c843-11ed-9688-891629944ff8",
"username": "dotnet_kernel",
"session": "e573978f-cab9-4392-a85d-a1f03c1d7de3",
"date": "2023-03-21T23:56:12.928329Z",
"msg_type": "status",
"version": "5.0"
},
"parent_header": {
"msg_id": "f0d294b7-12fb-4c83-ab58-2cb57847bbb5",
"username": "dotnet_kernel",
"session": "e573978f-cab9-4392-a85d-a1f03c1d7de3",
"date": "2023-03-21T23:56:12.8630296Z",
"msg_type": "kernel_info_request",
"version": "5.3"
},
"metadata": {},
"content": {
"execution_state": "busy"
},
"buffers": [],
"channel": "shell"
},
{
"header": {
"msg_id": "f5b95cda-c843-11ed-9688-891629944ff8",
"username": "dotnet_kernel",
"session": "e573978f-cab9-4392-a85d-a1f03c1d7de3",
"date": "2023-03-21T23:56:12.930338Z",
"msg_type": "kernel_info_reply",
"version": "5.0"
},
"parent_header": {
"msg_id": "f0d294b7-12fb-4c83-ab58-2cb57847bbb5",
"username": "dotnet_kernel",
"session": "e573978f-cab9-4392-a85d-a1f03c1d7de3",
"date": "2023-03-21T23:56:12.8630296Z",
"msg_type": "kernel_info_request",
"version": "5.3"
},
"metadata": {},
"content": {
"protocol_version": "5.0",
"implementation": "IRkernel",
"implementation_version": "0.8.15",
"language_info": {
"name": "R",
"version": "3.6.1",
"mimetype": "text/x-r-source",
"file_extension": ".r",
"pygments_lexer": "r",
"codemirror_mode": "r"
},
"banner": "R version 3.6.1 (2019-07-05)",
"status": "ok",
"help_links": []
},
"buffers": [],
"channel": "shell"
},
{
"header": {
"msg_id": "f5b9ab54-c843-11ed-9688-891629944ff8",
"username": "dotnet_kernel",
"session": "e573978f-cab9-4392-a85d-a1f03c1d7de3",
"date": "2023-03-21T23:56:12.932337Z",
"msg_type": "status",
"version": "5.0"
},
"parent_header": {
"msg_id": "f0d294b7-12fb-4c83-ab58-2cb57847bbb5",
"username": "dotnet_kernel",
"session": "e573978f-cab9-4392-a85d-a1f03c1d7de3",
"date": "2023-03-21T23:56:12.8630296Z",
"msg_type": "kernel_info_request",
"version": "5.3"
},
"metadata": {},
"content": {
"execution_state": "idle"
},
"buffers": [],
"channel": "shell"
},
{
"header": {
"msg_id": "f5bc9972-c843-11ed-9688-891629944ff8",
"username": "dotnet_kernel",
"session": "1df29cd2-86d7-4db4-88c1-0d9b31c03918",
"date": "2023-03-21T23:56:12.951541Z",
"msg_type": "status",
"version": "5.0"
},
"parent_header": {
"msg_id": "a6da1752-137d-4109-84cf-49ad7dc738e8",
"username": "dotnet_kernel",
"session": "1df29cd2-86d7-4db4-88c1-0d9b31c03918",
"date": "2023-03-21T23:56:12.9318012Z",
"msg_type": "execute_request",
"version": "5.3"
},
"metadata": {},
"content": {
"execution_state": "busy"
},
"buffers": [],
"channel": "shell"
},
{
"header": {
"msg_id": "f5bce792-c843-11ed-9688-891629944ff8",
"username": "dotnet_kernel",
"session": "1df29cd2-86d7-4db4-88c1-0d9b31c03918",
"date": "2023-03-21T23:56:12.953542Z",
"msg_type": "execute_input",
"version": "5.0"
},
"parent_header": {
"msg_id": "a6da1752-137d-4109-84cf-49ad7dc738e8",
"username": "dotnet_kernel",
"session": "1df29cd2-86d7-4db4-88c1-0d9b31c03918",
"date": "2023-03-21T23:56:12.9318012Z",
"msg_type": "execute_request",
"version": "5.3"
},
"metadata": {},
"content": {
"code": "# Copyright (c) .NET Foundation and contributors. All rights reserved.\n# Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nlibrary(IRkernel);\nlibrary(jsonlite);\n\n.dotnet_coe_comm_hander_env <- new.env();\n\n.dotnet_coe_comm_hander_env$emptyEvent <- fromJSON(\"{}\")\n\n# events\n.dotnet_coe_comm_hander_env$KernelReady <- 'KernelReady';\n.dotnet_coe_comm_hander_env$CommandSucceeded <- 'CommandSucceeded';\n.dotnet_coe_comm_hander_env$CommandFailed <- 'CommandFailed';\n.dotnet_coe_comm_hander_env$ValueProduced <- 'ValueProduced';\n.dotnet_coe_comm_hander_env$ValueInfosProduced <- 'ValueInfosProduced';\n\n#commands\n.dotnet_coe_comm_hander_env$SendValue <- 'SendValue';\n.dotnet_coe_comm_hander_env$RequestValue <- 'RequestValue';\n.dotnet_coe_comm_hander_env$RequestValueInfos <- 'RequestValueInfos';\n\n.dotnet_coe_comm_hander_env$json <- function(value) {\n return (toJSON(value, auto_unbox = TRUE, null=\"null\", force = TRUE))\n}\n \n.dotnet_coe_comm_hander_env$payload <- function(envelope, type) {\n payload <- list(commandOrEvent = .dotnet_coe_comm_hander_env$json(envelope), type = type);\n return (payload);\n}\n\n.dotnet_coe_comm_hander_env$eventEnvelope <- function(event, eventType, command = NA) {\n if (!is.na(command) && !is.null(command)) {\n # we don't care about routing slip here and there are some json serialization issues with R un-boxing\n # for now, let's remove it or make it empty\n command$routingSlip <- list()\n }\n envelope <- list(event=event, eventType=eventType, command=command);\n return (.dotnet_coe_comm_hander_env$payload(envelope, 'event'));\n}\n\n.dotnet_coe_comm_hander_env$is_ready <- function() {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n list(kernelInfos=list()), \n .dotnet_coe_comm_hander_env$KernelReady)\n );\n}\n\n.dotnet_coe_comm_hander_env$fail <- function(message = NA, command = NA) {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n list(message=message), \n .dotnet_coe_comm_hander_env$CommandFailed, \n command)\n );\n}\n\n.dotnet_coe_comm_hander_env$pass <- function(command = NA) {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n .dotnet_coe_comm_hander_env$emptyEvent, \n .dotnet_coe_comm_hander_env$CommandSucceeded, \n command)\n );\n}\n\n.dotnet_coe_comm_hander_env$get_formatted_value <- function(value, mimeType = 'application/json') {\n formattedValue = NULL\n if (is.data.frame(value)) {\n mimeType <- 'application/table-schema+json'\n formattedValue <- .dotnet_coe_comm_hander_env$json(head(value))\n } else if (mimeType == 'application/json') {\n formattedValue <- .dotnet_coe_comm_hander_env$json(value)\n }\n return (list(\n mimeType=mimeType,\n value=formattedValue\n ))\n}\n\n.dotnet_coe_comm_hander_env$handle_request_value_infos <- function(commandOrEvent) {\n variables <- ls(all=TRUE, globalenv()) # we only retrieve the global variables \n results <- list();\n \n for (var in variables) {\n if (!startsWith(var, '.')) {\n value <- get(var);\n type <- if (is.data.frame(value)) 'data.frame' else toString(typeof(value));\n if (type != 'closure') {\n formattedValue <- .dotnet_coe_comm_hander_env$get_formatted_value(value);\n results <- append(results, list(list(name=var, formattedValue=formattedValue, typeName=type)));\n }\n };\n };\n \n \n valueInfosProduced = list(valueInfos=results)\n \n response <- .dotnet_coe_comm_hander_env$eventEnvelope(\n valueInfosProduced, \n .dotnet_coe_comm_hander_env$ValueInfosProduced, \n commandOrEvent)\n}\n\n.dotnet_coe_comm_hander_env$handle_request_value <- function(commandOrEvent) {\n requestValue <- commandOrEvent$command\n mimeType <- requestValue$mimeType\n name <- requestValue$name\n \n if (is.na(name) || name == '' || !exists(name)) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Variable \"%s\" not found.', name))\n )\n }\n \n rawValue <- get(name);\n mimeType <- if (is.data.frame(rawValue)) 'application/table-schema+json' else mimeType;\n formattedValue <- .dotnet_coe_comm_hander_env$get_formatted_value(rawValue, mimeType);\n\n valueProduced = list(\n name=name, \n value=rawValue, \n formattedValue=formattedValue\n )\n response <- .dotnet_coe_comm_hander_env$eventEnvelope(\n valueProduced, \n .dotnet_coe_comm_hander_env$ValueProduced, \n commandOrEvent)\n \n return (response)\n}\n\n.dotnet_coe_comm_hander_env$handle_send_value <- function(commandOrEvent) {\n sendValue <- commandOrEvent$command\n mimeType <- sendValue$formattedValue$mimeType\n name <- sendValue$name\n rawValue <- sendValue$formattedValue$value\n resultValue = NA\n \n if (make.names(name) != name) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Invalid Identifier: \"%s\"', name))\n )\n }\n \n if (mimeType == 'application/table-schema+json') {\n resultValue <- fromJSON(rawValue)\n resultValue <- data.frame(resultValue$data)\n } else if (mimeType == 'application/json') {\n resultValue <- fromJSON(rawValue)\n } else {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Failed to set value for \"%s\". \"%s\" mimetype not supported.', name, mimeType))\n )\n }\n \n \n assign(name, resultValue, globalenv());\n return (.dotnet_coe_comm_hander_env$pass())\n}\n\n.dotnet_coe_comm_hander_env$handle_command <- function(commandOrEvent) {\n commandType <- commandOrEvent$commandType\n\n result <- .dotnet_coe_comm_hander_env$fail(\n sprintf('command \"%s\" not supported', commandType)\n )\n\n if (commandType == .dotnet_coe_comm_hander_env$SendValue) {\n result <- .dotnet_coe_comm_hander_env$handle_send_value(commandOrEvent)\n } else if (commandType == .dotnet_coe_comm_hander_env$RequestValue) {\n result <- .dotnet_coe_comm_hander_env$handle_request_value(commandOrEvent)\n } else if (commandType == .dotnet_coe_comm_hander_env$RequestValueInfos) {\n result <- .dotnet_coe_comm_hander_env$handle_request_value_infos(commandOrEvent)\n }\n\n return (result)\n}\n\n.dotnet_coe_comm_hander_env$handle_command_or_event <- function(msg) {\n response <- tryCatch({\n msg_type <- msg$type\n commandOrEvent <- fromJSON(msg$commandOrEvent)\n \n if (msg_type == 'command') {\n return (.dotnet_coe_comm_hander_env$handle_command(commandOrEvent))\n } \n },\n error=function(cond) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('failed to process comm data. %s', cond$message))\n )\n }) \n \n return(response)\n}\n\n.dotnet_coe_comm_hander_env$coe_handler_connect_to_comm <- function(comm, data) {\n comm$on_msg(function(msg) {\n # assign('.debug.onmsg', msg, globalenv());\n response <- .dotnet_coe_comm_hander_env$handle_command_or_event(msg);\n comm$send(response); \n })\n\n ready <- .dotnet_coe_comm_hander_env$is_ready()\n comm$send(ready); \n \n};\n\ncomm_manager()$register_target('dotnet_coe_handler_comm', .dotnet_coe_comm_hander_env$coe_handler_connect_to_comm);\n",
"execution_count": 1
},
"buffers": [],
"channel": "shell"
},
{
"header": {
"msg_id": "f5cd2b8e-c843-11ed-9688-891629944ff8",
"username": "dotnet_kernel",
"session": "1df29cd2-86d7-4db4-88c1-0d9b31c03918",
"date": "2023-03-21T23:56:13.060141Z",
"msg_type": "execute_reply",
"version": "5.0"
},
"parent_header": {
"msg_id": "a6da1752-137d-4109-84cf-49ad7dc738e8",
"username": "dotnet_kernel",
"session": "1df29cd2-86d7-4db4-88c1-0d9b31c03918",
"date": "2023-03-21T23:56:12.9318012Z",
"msg_type": "execute_request",
"version": "5.3"
},
"metadata": {},
"content": {
"payload": [],
"user_expressions": {},
"status": "ok",
"execution_count": 1
},
"buffers": [],
"channel": "shell"
},
{
"header": {
"msg_id": "f5cd529e-c843-11ed-9688-891629944ff8",
"username": "dotnet_kernel",
"session": "1df29cd2-86d7-4db4-88c1-0d9b31c03918",
"date": "2023-03-21T23:56:13.061143Z",
"msg_type": "status",
"version": "5.0"
},
"parent_header": {
"msg_id": "a6da1752-137d-4109-84cf-49ad7dc738e8",
"username": "dotnet_kernel",
"session": "1df29cd2-86d7-4db4-88c1-0d9b31c03918",
"date": "2023-03-21T23:56:12.9318012Z",
"msg_type": "execute_request",
"version": "5.3"
},
"metadata": {},
"content": {
"execution_state": "idle"
},
"buffers": [],
"channel": "shell"
},
{
"header": {
"msg_id": "f5cdeef2-c843-11ed-9688-891629944ff8",
"username": "dotnet_kernel",
"session": "a8364953-7c65-4b09-a16c-0db9ed40cd9c",
"date": "2023-03-21T23:56:13.064141Z",
"msg_type": "status",
"version": "5.0"
},
"parent_header": {
"msg_id": "61b38ad4-3044-4c89-8bb6-5b6c837da88d",
"username": "dotnet_kernel",
"session": "a8364953-7c65-4b09-a16c-0db9ed40cd9c",
"date": "2023-03-21T23:56:13.0615647Z",
"msg_type": "comm_open",
"version": "5.3"
},
"metadata": {},
"content": {
"execution_state": "busy"
},
"buffers": [],
"channel": "shell"
},
{
"header": {
"msg_id": "f5ce8b1e-c843-11ed-9688-891629944ff8",
"username": "dotnet_kernel",
"session": "a8364953-7c65-4b09-a16c-0db9ed40cd9c",
"date": "2023-03-21T23:56:13.068140Z",
"msg_type": "comm_msg",
"version": "5.0"
},
"parent_header": {
"msg_id": "61b38ad4-3044-4c89-8bb6-5b6c837da88d",
"username": "dotnet_kernel",
"session": "a8364953-7c65-4b09-a16c-0db9ed40cd9c",
"date": "2023-03-21T23:56:13.0615647Z",
"msg_type": "comm_open",
"version": "5.3"
},
"metadata": {},
"content": {
"comm_id": "92d4d6d7-809d-4b59-b52e-98dece235ea7",
"data": {
"commandOrEvent": "{\"event\":{\"kernelInfos\":[]},\"eventType\":\"KernelReady\",\"command\":null}",
"type": "event"
}
},
"buffers": [],
"channel": "shell"
},
{
"header": {
"msg_id": "f5ceb238-c843-11ed-9688-891629944ff8",
"username": "dotnet_kernel",
"session": "a8364953-7c65-4b09-a16c-0db9ed40cd9c",
"date": "2023-03-21T23:56:13.069140Z",
"msg_type": "status",
"version": "5.0"
},
"parent_header": {
"msg_id": "61b38ad4-3044-4c89-8bb6-5b6c837da88d",
"username": "dotnet_kernel",
"session": "a8364953-7c65-4b09-a16c-0db9ed40cd9c",
"date": "2023-03-21T23:56:13.0615647Z",
"msg_type": "comm_open",
"version": "5.3"
},
"metadata": {},
"content": {
"execution_state": "idle"
},
"buffers": [],
"channel": "shell"
}
]