Skip to content

Commit c5786cd

Browse files
committed
adding opt-ins to our notebook sample tests
1 parent 390b84d commit c5786cd

File tree

3 files changed

+61
-2
lines changed

3 files changed

+61
-2
lines changed

dataframe-jupyter/src/test/kotlin/org/jetbrains/kotlinx/dataframe/jupyter/DataFrameJupyterTest.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ import org.jetbrains.kotlinx.jupyter.testkit.ReplProvider
77
abstract class DataFrameJupyterTest :
88
JupyterReplTestCase(
99
ReplProvider.forLibrariesTesting(
10-
setOf("dataframe", "dataframe-jupyter"),
10+
libraries = setOf("dataframe", "dataframe-jupyter"),
11+
extraCompilerArguments = listOf(
12+
"-Xopt-in=kotlin.time.ExperimentalTime",
13+
"-Xopt-in=kotlin.uuid.ExperimentalUuidApi",
14+
),
1115
),
1216
)
1317

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package org.jetbrains.kotlinx.dataframe.jupyter
2+
3+
import org.jetbrains.kotlinx.jupyter.api.EmbeddedKernelRunMode
4+
import org.jetbrains.kotlinx.jupyter.config.DefaultKernelLoggerFactory
5+
import org.jetbrains.kotlinx.jupyter.config.defaultRepositoriesCoordinates
6+
import org.jetbrains.kotlinx.jupyter.libraries.LibraryResolver
7+
import org.jetbrains.kotlinx.jupyter.libraries.createLibraryHttpUtil
8+
import org.jetbrains.kotlinx.jupyter.repl.ReplForJupyter
9+
import org.jetbrains.kotlinx.jupyter.repl.creating.createRepl
10+
import org.jetbrains.kotlinx.jupyter.repl.embedded.NoOpInMemoryReplResultsHolder
11+
import org.jetbrains.kotlinx.jupyter.testkit.ClasspathLibraryResolver
12+
import org.jetbrains.kotlinx.jupyter.testkit.ReplProvider
13+
import org.jetbrains.kotlinx.jupyter.testkit.ToEmptyLibraryResolver
14+
15+
/** Mirrors [ReplProvider.forLibrariesTesting] but `extraCompilerArguments` to set opt-in's. */
16+
@Suppress("unused")
17+
fun ReplProvider.Companion.forLibrariesTesting(
18+
libraries: Collection<String>,
19+
extraCompilerArguments: List<String> = emptyList(),
20+
): ReplProvider =
21+
withDefaultClasspathResolution(
22+
shouldResolveToEmpty = { it in libraries },
23+
extraCompilerArguments = extraCompilerArguments,
24+
)
25+
26+
private val httpUtil = createLibraryHttpUtil(DefaultKernelLoggerFactory)
27+
28+
fun withDefaultClasspathResolution(
29+
shouldResolve: (String?) -> Boolean = { true },
30+
shouldResolveToEmpty: (String?) -> Boolean = { false },
31+
extraCompilerArguments: List<String> = emptyList(),
32+
) = ReplProvider { classpath ->
33+
val resolver =
34+
run {
35+
var res: LibraryResolver = ClasspathLibraryResolver(httpUtil.libraryDescriptorsManager, null, shouldResolve)
36+
res = ToEmptyLibraryResolver(res, shouldResolveToEmpty)
37+
res
38+
}
39+
40+
createRepl(
41+
httpUtil = httpUtil,
42+
scriptClasspath = classpath,
43+
kernelRunMode = EmbeddedKernelRunMode,
44+
mavenRepositories = defaultRepositoriesCoordinates,
45+
libraryResolver = resolver,
46+
inMemoryReplResultsHolder = NoOpInMemoryReplResultsHolder,
47+
extraCompilerArguments = extraCompilerArguments,
48+
).apply {
49+
initializeWithCurrentClasspath()
50+
}
51+
}
52+
53+
private fun ReplForJupyter.initializeWithCurrentClasspath() {
54+
eval { librariesScanner.addLibrariesFromClassLoader(currentClassLoader, this, notebook) }
55+
}

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.0-2.0.2"
3-
kotlinJupyter = "0.13.0-481-1"
3+
kotlinJupyter = "0.15.0-587"
44

55
ktlint = "12.3.0"
66

0 commit comments

Comments
 (0)