org.jetbrains.kotlinx.jupyter.config.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlin-jupyter-kernel Show documentation
Show all versions of kotlin-jupyter-kernel Show documentation
Kotlin Jupyter kernel published as artifact
package org.jetbrains.kotlinx.jupyter
import jupyter.kotlin.JavaRuntime
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encodeToString
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonPrimitive
import kotlinx.serialization.json.decodeFromJsonElement
import kotlinx.serialization.serializer
import org.jetbrains.kotlinx.jupyter.api.KotlinKernelVersion
import org.jetbrains.kotlinx.jupyter.common.getNameForUser
import org.jetbrains.kotlinx.jupyter.config.defaultRepositories
import org.jetbrains.kotlinx.jupyter.config.getLogger
import org.jetbrains.kotlinx.jupyter.config.readResourceAsIniFile
import org.jetbrains.kotlinx.jupyter.dependencies.ResolverConfig
import org.jetbrains.kotlinx.jupyter.libraries.ResolutionInfoProvider
import org.jetbrains.kotlinx.jupyter.libraries.getStandardResolver
import org.zeromq.SocketType
import java.io.File
const val protocolVersion = "5.3"
internal val log by lazy { getLogger() }
val defaultRuntimeProperties by lazy {
RuntimeKernelProperties(readResourceAsIniFile("runtime.properties"))
}
enum class JupyterSockets(val zmqKernelType: SocketType, val zmqClientType: SocketType) {
HB(SocketType.REP, SocketType.REQ),
SHELL(SocketType.ROUTER, SocketType.REQ),
CONTROL(SocketType.ROUTER, SocketType.REQ),
STDIN(SocketType.ROUTER, SocketType.REQ),
IOPUB(SocketType.PUB, SocketType.SUB);
val nameForUser = getNameForUser(name)
}
data class OutputConfig(
var captureOutput: Boolean = true,
var captureBufferTimeLimitMs: Long = 100,
var captureBufferMaxSize: Int = 1000,
var cellOutputMaxSize: Int = 100000,
var captureNewlineBufferSize: Int = 100
) {
fun update(other: OutputConfig) {
captureOutput = other.captureOutput
captureBufferTimeLimitMs = other.captureBufferTimeLimitMs
captureBufferMaxSize = other.captureBufferMaxSize
cellOutputMaxSize = other.cellOutputMaxSize
captureNewlineBufferSize = other.captureNewlineBufferSize
}
}
class RuntimeKernelProperties(val map: Map) : ReplRuntimeProperties {
override val version: KotlinKernelVersion? by lazy {
map["version"]?.let { KotlinKernelVersion.from(it) }
}
override val librariesFormatVersion: Int
get() = map["librariesFormatVersion"]?.toIntOrNull() ?: throw RuntimeException("Libraries format version is not specified!")
override val currentBranch: String
get() = map["currentBranch"] ?: throw RuntimeException("Current branch is not specified!")
override val currentSha: String
get() = map["currentSha"] ?: throw RuntimeException("Current commit SHA is not specified!")
override val jvmTargetForSnippets by lazy {
map["jvmTargetForSnippets"] ?: JavaRuntime.version
}
}
@Serializable(KernelJupyterParamsSerializer::class)
data class KernelJupyterParams(
val sigScheme: String?,
val key: String?,
val ports: List,
val transport: String?
) {
companion object {
fun fromFile(cfgFile: File): KernelJupyterParams {
val jsonString = cfgFile.canonicalFile.readText()
return Json.decodeFromString(jsonString)
}
}
}
object KernelJupyterParamsSerializer : KSerializer {
private val utilSerializer = serializer
© 2015 - 2025 Weber Informatics LLC | Privacy Policy