-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow REPL/Kernel to be embedded and share classes/variables with its caller #102
Conversation
I have been testing and using this for the past week and it works quite well, and allows some really powerful extensions to at least one Java GUI tool that I am using. The approach should be general enough that this also works for every other JVM project that wants to simply embed a kernel in its context. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that if it has real applications, this PR is OK, except one small thing. Please fix it and I'll merge it
@@ -83,6 +83,26 @@ class RuntimeKernelProperties(val map: Map<String, String>): ReplRuntimeProperti | |||
} | |||
} | |||
|
|||
data class KernelCfgFile( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that name KernelJupyterParams
fits better. Anyway, please rename this class to something without abbreviations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds like a good name, changed it.
This allows a Java application to create a Kotlin kernel based on the kernel-*.json and parameters. Otherwise it would have to create fake commandline arguments or parse the kernel-*.json itself
The testcases work for me locally, both |
Currently the Kotlin kernel supports something similar to IPython.start_kernel. This PR aims to support something that covers the use cases of IPython.embed_kernel.
What this PR provides
An application can now call
org.jetbrains.kotlin.jupyter.iKotlin.kernelServer
directly and pass a desiredKernelConfig
and the runtime properties where theembedded
property is set totrue
and return theKernelConfig
as a standard JSON to user in an application specific way.The user can then run
jupyter console --existing=path/to/kernelconfig.json
to attach a Kotlin REPL to the kernel and run arbitrary Kotlin code inside the application context with the same state as the the application.What this PR does not allow
This does not allow attaching a Jupyter Notebook to the Kernel. This is a limitation of Jupyter Notebooks and not the Kotlin kernel.
Status
This should work already, but I'm currently still writing the actual embedding code for the application I want to use it in, so until then I still consider this PR a draft, but appreciate an feedback on the general idea and current implementation.
EDIT:
The first proof of concept for this already works and I think anything else I wanted to achieve is an issue with the application embedding the kernel. This embedding could be simplified by allowing the embedding Java Application to acess
defaultRuntimeProperties
. I am also feeling unsure if the runtimeproperties is really the right place for the embedding option, and ifKernelArgs
/KernelConfig
wouldn't be a better place.