If I instead use the following code to create the kernel it works, despite the homeDir being a completely invalid directory:
var config = KernelConfig.Companion.fromConfig(
KernelJupyterParams.Companion.fromFile(connectionFile),
EmptyResolutionInfoProvider.INSTANCE,
cp,
new File("/NOTEXISTING/"),
true);
IkotlinKt.kernelServer(config, ConfigKt.getDefaultRuntimeProperties(), Collections.singletonList(context));
with this I can also run %use example in the kernel, and it will correctly load the file at /home/myusername/.jupyter_kotlin/libraries/example.json, so some other code knows the default homedir anyway.
Change the signature of embedKernel to allow passing a homeDir
I don't know what this homeDir value actually achieves, and it might be useful for code using embedKernel to correctly set this. But because a nullhomeDir doesn't raise an issues in my case it should probably be an optional parameter. And then it should IMO still be possible to load library definitions from a full path or from the .jupyter_kotlin/libraries/ directory even if no homeDir is passed.
All of the examples are on https://github.com/Kotlin/kotlin-jupyter/blob/stable-kotlin-2 but it doesn't look like this changed compared to current
master
Problem
Usually I embed the kernel via
but in the resulting kernel it is not possible to load a library definition, even if explicitly specifying a full path because in: https://github.com/Kotlin/kotlin-jupyter/blob/e5126191f53cb0a949d99d417fa60e8b8cbdb3ed/src/main/kotlin/org/jetbrains/kotlinx/jupyter/libraries/LibrariesProcessorImpl.kt#L66-L67
libraries
isnull
, and theReplException
is thrown.this happens because
embedKernel
passesnull
for ahomeDir
, https://github.com/Kotlin/kotlin-jupyter/blob/e5126191f53cb0a949d99d417fa60e8b8cbdb3ed/src/main/kotlin/org/jetbrains/kotlinx/jupyter/ikotlin.kt#L96then the
resolverConfig
isn't created: https://github.com/Kotlin/kotlin-jupyter/blob/e5126191f53cb0a949d99d417fa60e8b8cbdb3ed/src/main/kotlin/org/jetbrains/kotlinx/jupyter/config.kt#L164 and then there are no libraries to pass when theLibrariesProcessor
is constructed: https://github.com/Kotlin/kotlin-jupyter/blob/e5126191f53cb0a949d99d417fa60e8b8cbdb3ed/src/main/kotlin/org/jetbrains/kotlinx/jupyter/repl.kt#L242If I instead use the following code to create the kernel it works, despite the
homeDir
being a completely invalid directory:with this I can also run
%use example
in the kernel, and it will correctly load the file at/home/myusername/.jupyter_kotlin/libraries/example.json
, so some other code knows the default homedir anyway.Possible Fixes
Create
resolverConfig
withnull
homeDirloadResolverConfig
has a signature that requires the homeDir to be not null https://github.com/Kotlin/kotlin-jupyter/blob/e5126191f53cb0a949d99d417fa60e8b8cbdb3ed/src/main/kotlin/org/jetbrains/kotlinx/jupyter/config.kt#L172but the called
getStandardResolver
is fine with ahomeDir
ofnull
again.https://github.com/Kotlin/kotlin-jupyter/blob/e5126191f53cb0a949d99d417fa60e8b8cbdb3ed/src/main/kotlin/org/jetbrains/kotlinx/jupyter/libraries/resolutionUtil.kt#L14-L21
Change the signature of
embedKernel
to allow passing ahomeDir
I don't know what this
homeDir
value actually achieves, and it might be useful for code usingembedKernel
to correctly set this. But because anull
homeDir
doesn't raise an issues in my case it should probably be an optional parameter. And then it should IMO still be possible to load library definitions from a full path or from the.jupyter_kotlin/libraries/
directory even if nohomeDir
is passed.