Skip to content

Commit 64599d1

Browse files
committed
Move notebook metadata detection to compiler artifact
1 parent 1fe6cef commit 64599d1

File tree

5 files changed

+76
-33
lines changed

5 files changed

+76
-33
lines changed

jupyter-lib/shared-compiler/build.gradle.kts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import build.CreateResourcesTask
2+
import build.util.defaultVersionCatalog
3+
import build.util.devKotlin
24

35
plugins {
46
id("ru.ileasile.kotlin.publisher")
@@ -45,7 +47,13 @@ buildSettings {
4547
}
4648

4749
CreateResourcesTask.register(project, "buildProperties", tasks.processResources) {
48-
addPropertiesFile("compiler.properties", mapOf("version" to rootSettings.pyPackageVersion))
50+
addPropertiesFile(
51+
"compiler.properties",
52+
mapOf(
53+
"version" to rootSettings.pyPackageVersion,
54+
"kotlinVersion" to defaultVersionCatalog.versions.devKotlin,
55+
)
56+
)
4957
}
5058

5159
kotlinPublications {
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package org.jetbrains.kotlinx.jupyter.config
2+
3+
import kotlinx.serialization.SerialName
4+
import kotlinx.serialization.Serializable
5+
6+
@Serializable
7+
class LanguageInfo(
8+
val name: String,
9+
val version: String,
10+
val mimetype: String,
11+
12+
@SerialName("file_extension")
13+
val fileExtension: String,
14+
15+
@SerialName("pygments_lexer")
16+
val pygmentsLexer: String,
17+
18+
@SerialName("codemirror_mode")
19+
val codemirrorMode: String,
20+
21+
@SerialName("nbconvert_exporter")
22+
val nbConvertExporter: String,
23+
)
24+
25+
val notebookLanguageInfo: LanguageInfo by lazy {
26+
LanguageInfo(
27+
"kotlin",
28+
currentKotlinVersion,
29+
"text/x-kotlin",
30+
".kt",
31+
"kotlin",
32+
"kotlin",
33+
""
34+
)
35+
}
36+
37+
@Serializable
38+
class KotlinKernelSpec(
39+
@SerialName("display_name")
40+
val displayName: String,
41+
val language: String,
42+
val name: String,
43+
)
44+
45+
val notebookKernelSpec: KotlinKernelSpec by lazy {
46+
KotlinKernelSpec(
47+
"Kotlin",
48+
"kotlin",
49+
"kotlin",
50+
)
51+
}

jupyter-lib/shared-compiler/src/main/kotlin/org/jetbrains/kotlinx/jupyter/config/runtimeProperties.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,16 @@ private val runtimeProperties by lazy {
1515
readResourceAsIniFile("compiler.properties", KernelStreams::class.java.classLoader)
1616
}
1717

18+
fun getFromRuntimeProperties(property: String, propertyDescription: String): String {
19+
return runtimeProperties[property] ?: error("Compiler artifact should contain $propertyDescription")
20+
}
21+
1822
val currentKernelVersion by lazy {
1923
KotlinKernelVersion.from(
20-
runtimeProperties["version"] ?: error("Compiler artifact should contain version")
24+
getFromRuntimeProperties("version", "kernel version")
2125
)!!
2226
}
27+
28+
val currentKotlinVersion by lazy {
29+
getFromRuntimeProperties("kotlinVersion", "Kotlin version")
30+
}

src/main/kotlin/org/jetbrains/kotlinx/jupyter/message_types.kt

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import kotlinx.serialization.json.decodeFromJsonElement
2323
import kotlinx.serialization.json.encodeToJsonElement
2424
import kotlinx.serialization.json.jsonObject
2525
import kotlinx.serialization.serializer
26+
import org.jetbrains.kotlinx.jupyter.config.LanguageInfo
2627
import org.jetbrains.kotlinx.jupyter.exceptions.ReplException
2728
import kotlin.reflect.KClass
2829
import kotlin.reflect.full.createType
@@ -371,25 +372,6 @@ class HelpLink(
371372
val url: String,
372373
)
373374

374-
@Serializable
375-
class LanguageInfo(
376-
val name: String,
377-
val version: String,
378-
val mimetype: String,
379-
380-
@SerialName("file_extension")
381-
val fileExtension: String,
382-
383-
@SerialName("pygments_lexer")
384-
val pygmentsLexer: String,
385-
386-
@SerialName("codemirror_mode")
387-
val codemirrorMode: String,
388-
389-
@SerialName("nbconvert_exporter")
390-
val nbConvertExporter: String,
391-
)
392-
393375
@Serializable
394376
class KernelInfoReply(
395377
@SerialName("protocol_version")

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

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import kotlinx.serialization.json.Json
88
import kotlinx.serialization.json.JsonObject
99
import kotlinx.serialization.json.encodeToJsonElement
1010
import org.jetbrains.annotations.TestOnly
11-
import org.jetbrains.kotlin.config.KotlinCompilerVersion
1211
import org.jetbrains.kotlinx.jupyter.LoggingManagement.disableLogging
1312
import org.jetbrains.kotlinx.jupyter.LoggingManagement.mainLoggerLevel
1413
import org.jetbrains.kotlinx.jupyter.api.DisplayResult
@@ -21,6 +20,9 @@ import org.jetbrains.kotlinx.jupyter.api.textResult
2120
import org.jetbrains.kotlinx.jupyter.common.looksLikeReplCommand
2221
import org.jetbrains.kotlinx.jupyter.compiler.util.EvaluatedSnippetMetadata
2322
import org.jetbrains.kotlinx.jupyter.config.KernelStreams
23+
import org.jetbrains.kotlinx.jupyter.config.currentKernelVersion
24+
import org.jetbrains.kotlinx.jupyter.config.currentKotlinVersion
25+
import org.jetbrains.kotlinx.jupyter.config.notebookLanguageInfo
2426
import org.jetbrains.kotlinx.jupyter.exceptions.ReplCompilerException
2527
import org.jetbrains.kotlinx.jupyter.exceptions.ReplException
2628
import org.jetbrains.kotlinx.jupyter.repl.EvalResult
@@ -228,17 +230,9 @@ fun JupyterConnection.Socket.shellMessagesHandler(msg: Message, repl: ReplForJup
228230
content = KernelInfoReply(
229231
protocolVersion,
230232
"Kotlin",
231-
repl.runtimeProperties.version.toMaybeUnspecifiedString(),
232-
"Kotlin kernel v. ${repl.runtimeProperties.version.toMaybeUnspecifiedString()}, Kotlin v. ${KotlinCompilerVersion.VERSION}",
233-
LanguageInfo(
234-
"kotlin",
235-
KotlinCompilerVersion.VERSION,
236-
"text/x-kotlin",
237-
".kt",
238-
"kotlin",
239-
"kotlin",
240-
""
241-
),
233+
currentKernelVersion.toMaybeUnspecifiedString(),
234+
"Kotlin kernel v. ${currentKernelVersion.toMaybeUnspecifiedString()}, Kotlin v. $currentKotlinVersion",
235+
notebookLanguageInfo,
242236
listOf()
243237
),
244238
)

0 commit comments

Comments
 (0)