-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
feat(jupyter): support confirm
and prompt
in notebooks
#23592
feat(jupyter): support confirm
and prompt
in notebooks
#23592
Conversation
@rgbkrk 👋 I see you've been advising on the Jupyter side for Deno's kernel. If you have a moment to sanity check this for the approach I took re: jupyter protocols, I'd appreciate it. This PR enables Specifically, the way I did zmq_identities copying works, but is it the right way? Otherwise, I've taken what I saw as python's approach for input, which looks to be overriding Thanks for checking out this draft if you have availability 🙏 . I'm trying to bring feature parity for Deno notebooks with Python as the reference and I find myself relying on this functionality in python notebooks when used as operational runbooks. |
cli/ops/jupyter.rs
Outdated
* routing prefix as the execute_reply in order for the frontend to receive the message. | ||
* """ | ||
*/ | ||
last_request |
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.
AFAIK, I think this is correct.
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.
Thank you 👏
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.
Confirmed this by the way and incorporated it directly into the new library to make it easier to do.
Supports `confirm` and `prompt` with custom versions used when inside a Jupyter Notebook with Deno kernel. The desired behavior (per python reference and docs): * confirm or prompt will trigger kernel to request the frontend to get user's input and return it to backend for processing We accomplish this by creating custom versions of confirm and prompt that call into an op_jupyter_input rust function with access to the stdin_socket. `confirm` and `prompt` are instantiated in the jupyter specific TS interface, so they only override the standard functions in jupyter context. Jupyter requires us to clone zmq_identities for this "input_request" message as documented in comments: ``` * Using with_identities() because of jupyter client docs instruction * Requires cloning identities per : * https://jupyter-client.readthedocs.io/en/latest/messaging.html#messages-on-the-stdin-router-dealer-channel * The stdin socket of the client is required to have the * same zmq IDENTITY as the client’s shell socket. * Because of this, the input_request must be sent with the same IDENTITY * routing prefix as the execute_reply in order for the frontend to receive the message. ```
9d07554
to
1cd77e2
Compare
1cd77e2
to
2162e33
Compare
☹ leading whitespace on PR title. Pushing fix :) Thanks for bumping this to kick off CI @dsherret! I've been enjoying using dax also as part of these notebooks. |
confirm
and prompt
in notebooksconfirm
and prompt
in notebooks
confirm
and prompt
in notebooksconfirm
and prompt
in notebooks
cli/tools/jupyter/jupyter_msg.rs
Outdated
pub(crate) fn allow_stdin(&self) -> bool { | ||
self.content["allow_stdin"].as_bool().unwrap_or(false) | ||
} | ||
|
||
pub(crate) fn value(&self) -> &str { | ||
self.content["value"].as_str().unwrap_or("") | ||
} |
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.
Are you sure that these values are always present in the Jupyter messages? If not, we should use self.content.get(...)
instead and provide default values that are "falsy".
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.
Really nice work @zph! This is a great improvement to our Jupyter kernel support 👍
Now that #23592 has landed I think we are ready to rewrite op_jupyter_input
to be a synchronous op and finalize this PR so it can land in Deno v1.44.
Let me know if you need any help with rebasing and/or turning that op into a sync code.
Great! I'll look at it this weekend and see if I can get it working |
I've done some deeper typing of the jupyter structures into a library we can share across projects and integrated it with deno here: #23826 It'll be great to bring your work directly into it. |
Awesome! I'll wait a bit for yours to land :) and then happy to incorporate/build-on. |
Landed #23826! You can either rebase/merge main or kick off a new PR. Feel free to ping me, I'm happy to help. |
Awesome, thanks @rgbkrk |
You're welcome to push on to this PR! 😁
…On Sun, Jun 30, 2024, at 17:24, Bartek Iwańczuk wrote:
@zph <https://github.com/zph> I got this working using #24373 <#24373>. Do you want me to push to your PR or open a new one based on your code?
—
Reply to this email directly, view it on GitHub <#23592 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAH2UGEZI5ZVAKLYCZHIHMDZKCOSZAVCNFSM6AAAAABG5FCNT2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOJYHAZDMMZSGM>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
--
Zander
GH: @zph || https://blog.xargs.io
|
@bartlomieju I'm excited you got it working! I took a few hours on it but didn't make much progress and think I need more rust under my belt to solve it after the earlier refactor. This will be awesome to see in the language and it's cool that some base of my code will make it into deno |
Great, I will do just that.
No worries, you tackled a really tough one which looked easy on the surface. Kudos for
Keep it coming! |
I'm gonna land it as is and add tests in a follow up PR, because they require to rewrite a bunch of testing infra and I want to land changes from #24250 first. |
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.
LGTM, exciting work @zph! Thanks for the PR
Awesome! Thank you for carrying this along 😺. I'll pull it down and take it for a spin. |
Confirmed looks good in:
|
…24373) Moves the ZeroMQ messaging server to a separate thread. This will allow to run blocking JS code and maintain communication with the notebook frontend. Towards denoland#23592 Towards denoland#24250 Closes denoland#23617
…23592) Closes: denoland#22633 This commit adds support for `confirm` and `prompt` APIs, that instead of reading from stdin are using notebook frontend to show modal boxes and wait for answers. --------- Co-authored-by: Bartek Iwańczuk <[email protected]>
Closes: #22633
Supports
confirm
andprompt
with custom versions used when inside a Jupyter Notebook with Deno kernel.The desired behavior (per python reference and docs):
We accomplish this by creating custom versions of confirm and prompt that call into an op_jupyter_input rust function with access to the stdin_socket.
confirm
andprompt
are instantiated in the jupyter specific TS interface, so they only override the standard functions in jupyter context.Jupyter requires us to clone zmq_identities for this "input_request" message as documented in comments:
TODO
PR guidelines
cargo test
passes../tools/format.js
passes without changing files../tools/lint.js
passes.all steps, but you can add '[ci]' to a commit message to force it to.
If you would like to run the benchmarks on the CI, add the 'ci-bench' label.