Skip to content

Commit 334178a

Browse files
committed
Fix post-rebase errors
1 parent 69e949c commit 334178a

File tree

3 files changed

+38
-53
lines changed
  • jupyter-lib/kotlin-jupyter-api/src/main/kotlin/org/jetbrains/kotlin/jupyter/api
  • src/main/kotlin/org/jetbrains/kotlin/jupyter

3 files changed

+38
-53
lines changed

jupyter-lib/kotlin-jupyter-api/src/main/kotlin/org/jetbrains/kotlin/jupyter/api/results.kt

+10-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ interface Renderable {
99
interface DisplayResult: Renderable {
1010
val id: String? get() = null
1111

12-
fun toJson(): JsonObject
12+
fun toJson(additionalMetadata: JsonObject = jsonObject()): JsonObject
1313

1414
override fun render(notebook: Notebook<*>) = this
1515
}
@@ -23,6 +23,7 @@ interface DisplayContainer {
2323
fun getById(id: String?): List<DisplayResultWithCell>
2424
}
2525

26+
@Suppress("unused")
2627
fun DisplayResult?.toJson(): JsonObject {
2728
if (this != null) return this.toJson()
2829
return jsonObject("data" to null, "metadata" to jsonObject())
@@ -48,9 +49,13 @@ class MimeTypedResult(
4849
var isolatedHtml: Boolean = false,
4950
override val id: String? = null
5051
) : Map<String, String> by mimeData, DisplayResult {
51-
override fun toJson(): JsonObject {
52+
override fun toJson(additionalMetadata: JsonObject): JsonObject {
5253
val data = JsonObject(this)
5354
val metadata = if (isolatedHtml) jsonObject("text/html" to jsonObject("isolated" to true)) else jsonObject()
55+
additionalMetadata.forEach { key, value ->
56+
metadata[key] = value
57+
}
58+
5459
val result = jsonObject(
5560
"data" to data,
5661
"metadata" to metadata
@@ -60,7 +65,10 @@ class MimeTypedResult(
6065
}
6166
}
6267

68+
@Suppress("unused", "FunctionName")
6369
fun MIME(vararg mimeToData: Pair<String, String>): MimeTypedResult = mimeResult(*mimeToData)
70+
71+
@Suppress("unused", "FunctionName")
6472
fun HTML(text: String, isolated: Boolean = false) = htmlResult(text, isolated)
6573

6674
fun mimeResult(vararg mimeToData: Pair<String, String>): MimeTypedResult = MimeTypedResult(mapOf(*mimeToData))

src/main/kotlin/org/jetbrains/kotlin/jupyter/protocol.kt

+28-39
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,38 @@ abstract class Response(
4848
}
4949

5050
class OkResponseWithMessage(
51-
private val result: MimeTypedResult?,
51+
private val result: DisplayResult?,
5252
private val newClasspath: Classpath = emptyList(),
5353
stdOut: String? = null,
5454
stdErr: String? = null,
5555
): Response(stdOut, stdErr){
56+
override val state: ResponseState = ResponseState.Ok
57+
58+
override fun sendBody(socket: JupyterConnection.Socket, requestCount: Long, requestMsg: Message, startedTime: String) {
59+
if (result != null) {
60+
val metadata = jsonObject("new_classpath" to newClasspath)
61+
val resultJson = result.toJson(metadata).also { it["execution_count"] = requestCount }
62+
63+
socket.connection.iopub.send(makeReplyMessage(requestMsg,
64+
"execute_result",
65+
content = resultJson))
66+
}
67+
68+
socket.send(makeReplyMessage(requestMsg, "execute_reply",
69+
metadata = jsonObject(
70+
"dependencies_met" to true,
71+
"engine" to requestMsg.header["session"],
72+
"status" to "ok",
73+
"started" to startedTime),
74+
content = jsonObject(
75+
"status" to "ok",
76+
"execution_count" to requestCount,
77+
"user_variables" to JsonObject(),
78+
"payload" to listOf<String>(),
79+
"user_expressions" to JsonObject())))
80+
}
81+
82+
}
5683
interface DisplayHandler {
5784
fun handleDisplay(value: Any)
5885
fun handleUpdate(value: Any, id: String? = null)
@@ -88,45 +115,8 @@ class SocketDisplayHandler(
88115
}
89116
}
90117

91-
data class OkResponseWithMessage(
92-
val result: DisplayResult?,
93-
override val stdOut: String? = null,
94-
override val stdErr: String? = null,
95-
): Response{
96-
override val state: ResponseState = ResponseState.Ok
97-
98-
override fun sendBody(socket: JupyterConnection.Socket, requestCount: Long, requestMsg: Message, startedTime: String) {
99-
if (result != null) {
100-
val metadata = jsonObject()
101-
if (result.isolatedHtml) metadata["text/html"] = jsonObject("isolated" to true)
102-
metadata["new_classpath"] = newClasspath
103-
104-
socket.connection.iopub.send(makeReplyMessage(requestMsg,
105-
"execute_result",
106-
content = jsonObject(
107-
"execution_count" to requestCount,
108-
"data" to result,
109-
"metadata" to metadata
110-
)))
111-
}
112-
113-
socket.send(makeReplyMessage(requestMsg, "execute_reply",
114-
metadata = jsonObject(
115-
"dependencies_met" to true,
116-
"engine" to requestMsg.header["session"],
117-
"status" to "ok",
118-
"started" to startedTime),
119-
content = jsonObject(
120-
"status" to "ok",
121-
"execution_count" to requestCount,
122-
"user_variables" to JsonObject(),
123-
"payload" to listOf<String>(),
124-
"user_expressions" to JsonObject())))
125-
}
126-
}
127118

128119
class AbortResponseWithMessage(
129-
val result: MimeTypedResult?,
130120
stdErr: String? = null,
131121
): Response(null, stdErr){
132122
override val state: ResponseState = ResponseState.Abort
@@ -142,7 +132,6 @@ class AbortResponseWithMessage(
142132
}
143133

144134
class ErrorResponseWithMessage(
145-
val result: MimeTypedResult?,
146135
stdErr: String? = null,
147136
private val errorName: String = "Unknown error",
148137
private var errorValue: String = "",

src/main/kotlin/org/jetbrains/kotlin/jupyter/repl.kt

-12
Original file line numberDiff line numberDiff line change
@@ -459,17 +459,12 @@ class ReplForJupyterImpl(
459459
executeScheduledCode()
460460
}
461461

462-
log.catchAll {
463-
updateOutputList(jupyterId, result)
464-
}
465-
466462
val newClasspath = log.catchAll {
467463
updateClasspath()
468464
} ?: emptyList()
469465

470466
result = renderResult(result, resultField)
471467

472-
473468
return EvalResult(result, newClasspath)
474469

475470
} finally {
@@ -483,13 +478,6 @@ class ReplForJupyterImpl(
483478
return shutdownCodes.map(::evalWithReturn)
484479
}
485480

486-
private fun updateOutputList(jupyterId: Int, result: Any?) {
487-
if (jupyterId >= 0) {
488-
while (ReplOutputs.count() <= jupyterId) ReplOutputs.add(null)
489-
ReplOutputs[jupyterId] = result
490-
}
491-
}
492-
493481
/**
494482
* Updates current classpath with newly resolved libraries paths
495483
* Also, prints information about resolved libraries to stdout if [trackClasspath] is true

0 commit comments

Comments
 (0)