Skip to content

Commit 938a88f

Browse files
authored
Merge pull request #1415 from Kotlin/load-jupyter-from-core
Load dataframe-jupyter from core in notebooks
2 parents 3c01503 + 7a5cf9b commit 938a88f

File tree

5 files changed

+62
-3
lines changed

5 files changed

+62
-3
lines changed

CONTRIBUTING.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ This library is built with Gradle.
112112
making local publishing faster: `./gradlew publishToMavenLocal -PskipKodex`.
113113
This, however, publishes the library with "broken" KDocs,
114114
so it's only meant for faster iterations during development.
115+
* The parameter `-PincludeCoreLibrariesJson` makes the build include the `libraries.json` file in the `:core` module.
116+
This file allows loading dataframe-jupyter when dataframe-core is present on its own in a Kotlin Notebook.
117+
Usually only done when publishing.
115118

116119
You can import this project into IDEA, but you have to delegate the build actions
117120
to Gradle (in Preferences -> Build, Execution, Deployment -> Build Tools -> Gradle -> Runner)

core/build.gradle.kts

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import com.google.devtools.ksp.gradle.KspTaskJvm
33
import io.github.devcrocod.korro.KorroTask
44
import nl.jolanrensen.kodex.gradle.creatingRunKodexTask
55
import org.gradle.jvm.tasks.Jar
6-
import org.gradle.kotlin.dsl.withType
6+
import org.intellij.lang.annotations.Language
77
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
88

99
plugins {
@@ -251,6 +251,53 @@ val changeJarTask by tasks.registering {
251251
}
252252
}
253253

254+
// generateLibrariesJson makes sure a META-INF/kotlin-jupyter-libraries/libraries.json file is generated
255+
// This file allows loading dataframe-jupyter when dataframe-core is present on its own in a Kotlin Notebook.
256+
val generatedJupyterResourcesDir = layout.buildDirectory.dir("generated/jupyter")
257+
val generateLibrariesJson by tasks.registering {
258+
val outDir = generatedJupyterResourcesDir.get().asFile.resolve("META-INF/kotlin-jupyter-libraries")
259+
val outFile = outDir.resolve("libraries.json")
260+
outputs.file(outFile)
261+
inputs.property("version", project.version)
262+
263+
doLast {
264+
outDir.mkdirs()
265+
@Language("json")
266+
val content =
267+
"""
268+
{
269+
"descriptors": [
270+
{
271+
"init": [
272+
"USE { dependencies(\"org.jetbrains.kotlinx:dataframe-jupyter:${project.version}\") }"
273+
]
274+
}
275+
]
276+
}
277+
""".trimIndent()
278+
279+
outFile.delete()
280+
outFile.writeText(content)
281+
logger.lifecycle("generated META-INF/kotlin-jupyter-libraries/libraries.json for :core")
282+
}
283+
}
284+
285+
// If `includeCoreLibrariesJson` is set, modify the processResources task such that it includes
286+
// a META-INF libraries.json file.
287+
// This file allows loading dataframe-jupyter when dataframe-core is present on its own in a Kotlin Notebook.
288+
// This is usually only done when publishing.
289+
tasks.processResources {
290+
if (project.hasProperty("includeCoreLibrariesJson")) {
291+
dependsOn(generateLibrariesJson)
292+
from(generatedJupyterResourcesDir) {
293+
into("") // keep META-INF/... structure as generated
294+
}
295+
doLast {
296+
logger.lifecycle("$this includes generated META-INF/kotlin-jupyter-libraries/libraries.json")
297+
}
298+
}
299+
}
300+
254301
// if `processKDocsMain` runs, the Jar tasks must run after it so the generated-sources are there
255302
tasks.withType<Jar> {
256303
mustRunAfter(changeJarTask, tasks.generateKeywordsSrc, processKDocsMain)

dataframe-jupyter/src/main/kotlin/org/jetbrains/kotlinx/dataframe/jupyter/Integration.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ import kotlin.reflect.KType
5656
import kotlin.reflect.full.isSubtypeOf
5757

5858
/** Users will get an error if their Kotlin Jupyter kernel is older than this version. */
59-
private const val MIN_KERNEL_VERSION = "0.11.0.198"
59+
private const val MIN_KERNEL_VERSION = "0.15.0.606"
6060

6161
internal val newDataSchemas = mutableListOf<KClass<*>>()
6262

gradle.properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,12 @@ ksp.useKSP2=false
2222
kotlin.dataframe.debug=false
2323

2424
kotlin.incremental=false
25+
26+
# Can speed up build time but stops KDocs from being preprocessed.
27+
# It can also be turned on from the command line with `-PskipKodex`
28+
# skipKodex=true
29+
30+
# If `true`, builds include the core/src/main/resources/META-INF/kotlin-jupyter-libraries/libraries.json file.
31+
# This file allows loading dataframe-jupyter when dataframe-core is present on its own in a Kotlin Notebook.
32+
# This is usually only done when publishing and can be turned on from the command line with `-PincludeCoreLibrariesJson`
33+
# includeCoreLibrariesJson=true

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[versions]
22
ksp = "2.2.20-2.0.2"
3-
kotlinJupyter = "0.15.0-587"
3+
kotlinJupyter = "0.15.0-629"
44

55
ktlint = "12.3.0"
66

0 commit comments

Comments
 (0)