Skip to content

Commit 38e4691

Browse files
nikolay-egorovileasile
authored andcommitted
Add variable serializer to repl state; fixed some tests
1 parent 1ded90c commit 38e4691

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
@@ -143,6 +142,8 @@ interface ReplForJupyter {
143142

144143
val notebook: NotebookImpl
145144

145+
val variablesSerializer: VariablesSerializer
146+
146147
val fileExtension: String
147148

148149
val isEmbedded: Boolean
@@ -194,7 +195,9 @@ class ReplForJupyterImpl(
194195

195196
override val notebook = NotebookImpl(runtimeProperties)
196197

197-
val librariesScanner = LibrariesScanner(notebook)
198+
override val variablesSerializer = VariablesSerializer()
199+
200+
private val librariesScanner = LibrariesScanner(notebook)
198201
private val resourcesProcessor = LibraryResourcesProcessorImpl()
199202

200203
override var outputConfig
@@ -429,6 +432,9 @@ class ReplForJupyterImpl(
429432
notebook.updateVariablesState(internalEvaluator)
430433
// printVars()
431434
// printUsagesInfo(jupyterId, cellVariables[jupyterId - 1])
435+
val entry = notebook.variablesState.entries.lastOrNull()
436+
val serializedVarsState = variablesSerializer.serializeVariableState(jupyterId - 1, entry?.key, entry?.value)
437+
val serializedData = variablesSerializer.serializeVariables(jupyterId - 1, notebook.variablesState)
432438

433439

434440
val variablesStateUpdate = notebook.variablesState.mapValues { "" }
@@ -437,7 +443,7 @@ class ReplForJupyterImpl(
437443
rendered,
438444
result.scriptInstance,
439445
result.result.name,
440-
EvaluatedSnippetMetadata(newClasspath, compiledData, newImports, SerializedVariablesState()),
446+
EvaluatedSnippetMetadata(newClasspath, compiledData, newImports, serializedData),
441447
)
442448
}
443449
}

0 commit comments

Comments
 (0)