-
Notifications
You must be signed in to change notification settings - Fork 276
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
[do not merge] Naive JS Comms #141
base: main
Are you sure you want to change the base?
Conversation
Gross:
|
Really neat, thanks for starting this! |
Playing around on the RTD preview: js-widgets.mp4 |
You're amazing! |
@jtpio can you share a link to the RTD preview? |
app/lab/package.json
Outdated
@@ -54,6 +54,7 @@ | |||
"@jupyterlab/mathjax2-extension": "^3.1.0-alpha.11", | |||
"@jupyterlab/notebook": "^3.1.0-alpha.11", | |||
"@jupyterlab/notebook-extension": "^3.1.0-alpha.11", | |||
"@jupyterlab/outputarea": "^3.1.0-alpha.11", |
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.
This one should be fixed on main
now.
We should find a way to plug your comm implementation to ipywidgets. Do you think monkey patching ipykernel could be enough? something like The only problem is ipywidgets bringing ipykernel, we should install ipywidgets ignoring dependencies. I don't know if conda can do that. |
Maybe a shim will be enough? That would mean creating a pure python package for |
Yeah, I dunno just yet about how to make this quack right in pyolite with actual packages... it'll be interesting, of course, but maybe still outside the scope of this PR. |
@@ -102,6 +135,15 @@ export abstract class BaseKernel implements IKernel { | |||
case 'history_request': | |||
await this._historyRequest(msg); | |||
break; | |||
case 'comm_open': | |||
await this._comm_manager.comm_open(msg); |
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.
Wondering whether we should adopt the same pattern as for the other messages, by having methods on the IKernel
interface?
For example with commOpen
, commMsg
and commClose
.
This could allow other kernels to completely change the implementation of the comm manager if they want, or just forward messages in the case of the Python kernel reusing the existing comm implementation.
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.
Yeah, as i mentioned, i'm still figuring out the architecture. the joke was, of course, first try to sneak into how one might get this into pyolite, realizing that was way crazy, and then unwrapping the actual flow of messages through the system to get to something that works.
This would of course need to move into its own package, but no reason not to have the API in better shape...
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.
In the pyolite PR https://github.com/jtpio/jupyterlite/pull/145, the approach I took was to more-or-less copy/paste the ipykernel comm implementation (which we could make a separate package so that both ipykernel and pyolite could use it).
This means the comm implementation is in Python, and lower in the architecture. So the approach to make those methods abstract as Jeremy is suggesting makes sense.
Now I am wondering if it's feasible and if it makes sense to reuse @bollwyvl 's JS implementation of the comms instead, we would need to expose those comms to the "Python process".
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.
Now I am wondering if it's feasible and if it makes sense to reuse @bollwyvl 's JS implementation of the comms instead, we would need to expose those comms to the "Python process".
In theory probably yes (or hopefully yes), if the JS implementations follow what ipykernel expects. This could be passed as a custom Python package from JavaScript: https://pyodide.org/en/stable/usage/faq.html#how-do-i-create-custom-python-packages-from-javascript
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.
Right, I think we win if these two PRs can be harmonized, but prettied up, moved to some new packages....
packages/
kernel/
kernel.ts # gets the comm(Open|Msg|Close)Msg handlers
js-kernel/
kernel.ts # has new CommManager({kernel: this})
py-kernel/src/
worker.ts # also needs CommManager in here...
kernel.ts # ... injects it here e.g. `import js; (await js.import(${COMM_URL})).CommManager`
py/.../
patches.py # sys.modules hacks, as on #145
# ...and the shim to do-async everything from #141 js
comms/src/
comm.ts
comm-manager.ts
providers/
memory.ts
# TODO: localForage.ts
# TODO: yjs.ts
In patches.py
, there are probably some more pointy bits... At the pyolite
/import js
boundary we need it to pretty much be dumb JSON types and Array
s, but it should be feasible.
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'll hoist this back to #18
So this... kinda re-implements ipykernel's CommManager, and slaps it on all the kernels, plus adds some widgets.
I am still getting my feet under me as to the local approaches vs previous endeavors, and will admit there was even more
as any
going on, but it's kinda into shape, from a soundness perspective 😊.References
Code changes
DefaultCommManager
to all kernelsHasTraits
Widget
FloatSlider
widget.observe
link
dlink
jslink
jsdlink
Textarea
Select
HTML
Upload
(for buffers?)interact
?self.kernel
, andwidgets
, pretty much defeating the iframe isolation 😱User-facing changes
Users of the docs site would be able to use at least a couple
FloatSlider
s in JS 😉 :I did originally dogfood the whole thing in a JupyterLite JS notebook... it was kind of hair-raising, and we gotta work on our persistence game.
Backwards-incompatible changes
Future Work
daughter-of-pyolite
Rename the Pyolite kernel #116 across theWebWorker
divideipykernel
,ipython
,ipywidget
shimslocalForage