-
Notifications
You must be signed in to change notification settings - Fork 17
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
Support stdin output #233
base: main
Are you sure you want to change the base?
Support stdin output #233
Changes from 2 commits
d9d7e32
e0b747a
c0eaa85
04ab4de
7c55532
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Copyright (c) Jupyter Development Team. | ||
# Distributed under the terms of the Modified BSD License. | ||
|
||
from pycrdt import Map, Text | ||
|
||
|
||
def add_stdin(cell: Map, prompt: str = "", password: bool = False) -> None: | ||
""" | ||
Adds an stdin Map in the cell outputs. | ||
|
||
Schema: | ||
|
||
.. code-block:: json | ||
|
||
{ | ||
"state": Map[ | ||
"pending": bool, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there are no non-pending inputs, they get cleared away once the result was submitted. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Though maybe there will be fore example if the kernel dies. Should we then clear the input box or keep it with some kind of disconnected icon? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By "pending" I meant that the input is in a "being edited" state or a "submitted" state, in which case it cannot be edited again. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In this case I guess we should just remove the |
||
"password": bool | ||
], | ||
"prompt": str, | ||
"input": Text | ||
} | ||
""" | ||
stdin = Map( | ||
{ | ||
"output_type": "stdin", | ||
"state": { | ||
"pending": True, | ||
"password": password, | ||
}, | ||
"prompt": prompt, | ||
"input": Text(), | ||
} | ||
) | ||
outputs = cell.get("outputs") | ||
outputs.append(stdin) |
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 is a question we do not need to answer now: should there be an owner of the input box too? So that the input can be provided only by the user who executed the code.
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.
If we think inputs are collaborative, then anybody should be able to fill them, right?
Otherwise I don't think this is really compatible with CRDTs, that are essentially shared structures.
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.
A teacher may want students to see what they are typing, but not allow students to type in into their box.
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.
At first sight it looks like the same issue as with cell code: there is no way to prevent a student from changing the code. Why would it be different with a input? If it's because it's the teacher who executed the cell, well this information is not present in the shared model, and I don't think it should be. And anyway, a student can re-execute the cell, and now should they be able to type in into the box? It doesn't really make sense.
A clearer model would be that the whole notebook is read-only for students. In this case we could ignore their Y-updates so that they can't change the shared model. This would make use of user permissions.
This is a general constraint of CRDTs, everybody sees the same data, unlike in a server/client architecture where a client makes a request and receives a dedicated reply. For instance, paginated results are possible with HTTP but not with CRDTs.