Skip to content

Commit b7bc217

Browse files
Add variable serializer to repl state; fixed some tests
1 parent ec5abc1 commit b7bc217

File tree

4 files changed

+283
-128
lines changed

4 files changed

+283
-128
lines changed

jupyter-lib/shared-compiler/src/main/kotlin/org/jetbrains/kotlinx/jupyter/compiler/util/serializedCompiledScript.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class EvaluatedSnippetMetadata(
3636
val newClasspath: Classpath = emptyList(),
3737
val compiledData: SerializedCompiledScriptsData = SerializedCompiledScriptsData.EMPTY,
3838
val newImports: List<String> = emptyList(),
39-
val evaluatedVariablesState: SerializedVariablesState = SerializedVariablesState()
39+
val evaluatedVariablesState: Map<String, SerializedVariablesState> = emptyMap()
4040
) {
4141
companion object {
4242
val EMPTY = EvaluatedSnippetMetadata()

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import org.jetbrains.kotlinx.jupyter.compiler.ScriptImportsCollector
2727
import org.jetbrains.kotlinx.jupyter.compiler.util.Classpath
2828
import org.jetbrains.kotlinx.jupyter.compiler.util.EvaluatedSnippetMetadata
2929
import org.jetbrains.kotlinx.jupyter.compiler.util.SerializedCompiledScriptsData
30-
import org.jetbrains.kotlinx.jupyter.compiler.util.SerializedVariablesState
3130
import org.jetbrains.kotlinx.jupyter.config.catchAll
3231
import org.jetbrains.kotlinx.jupyter.config.getCompilationConfiguration
3332
import org.jetbrains.kotlinx.jupyter.dependencies.JupyterScriptDependenciesResolverImpl
@@ -134,6 +133,8 @@ interface ReplForJupyter {
134133

135134
val notebook: NotebookImpl
136135

136+
val variablesSerializer: VariablesSerializer
137+
137138
val fileExtension: String
138139

139140
val isEmbedded: Boolean
@@ -185,7 +186,9 @@ class ReplForJupyterImpl(
185186

186187
override val notebook = NotebookImpl(runtimeProperties)
187188

188-
val librariesScanner = LibrariesScanner(notebook)
189+
override val variablesSerializer = VariablesSerializer()
190+
191+
private val librariesScanner = LibrariesScanner(notebook)
189192
private val resourcesProcessor = LibraryResourcesProcessorImpl()
190193

191194
override var outputConfig
@@ -418,6 +421,9 @@ class ReplForJupyterImpl(
418421
notebook.updateVariablesState(internalEvaluator)
419422
// printVars()
420423
// printUsagesInfo(jupyterId, cellVariables[jupyterId - 1])
424+
val entry = notebook.variablesState.entries.lastOrNull()
425+
val serializedVarsState = variablesSerializer.serializeVariableState(jupyterId - 1, entry?.key, entry?.value)
426+
val serializedData = variablesSerializer.serializeVariables(jupyterId - 1, notebook.variablesState)
421427

422428

423429
val variablesStateUpdate = notebook.variablesState.mapValues { "" }
@@ -426,7 +432,7 @@ class ReplForJupyterImpl(
426432
rendered,
427433
result.scriptInstance,
428434
result.result.name,
429-
EvaluatedSnippetMetadata(newClasspath, compiledData, newImports, SerializedVariablesState()),
435+
EvaluatedSnippetMetadata(newClasspath, compiledData, newImports, serializedData),
430436
)
431437
}
432438
}

0 commit comments

Comments
 (0)