-
-
Notifications
You must be signed in to change notification settings - Fork 836
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
Implement more detailed streams support #3268
Conversation
@ryanking13 could you review this if you get a chance? |
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.
Thanks for working on this @hoodmane! I have some minor comments (mostly questions), otherwise LGTM.
Co-authored-by: Gyeongjae Choi <def6488@gmail.com>
@rth Would you mind reading my description in the PR and reviewing the names / logic there? I think I will change |
Thanks for working on this @hoodmane ! A couple of comments/questions:
On what basis do we decide this? For instance from what I understood https://www.npmjs.com/package/dash-wasm is a real terminal not a JS one like we had, which runs in the browser (see related docs). So in that case the isatty would be True. So it seems to be it's not just about being in the browser or not, no? Edit: though, yes, I guess it's tied to The last comment would you mind adding a documentation section somewhere under |
I can do this, yes.
Yeah that is a reasonable option. The reason I didn't go this way is that
In order to write to
we have to collect up the calls to Another point of I am adding here
Well it's certainly conceptually related but I haven't thought too much about the details. One interesting idea is that we could have the message handlers be file descriptors that we write messages to. Then we could use the same sort of api for setting up the handlers for the file descriptors. I'm not sure that this is a good idea, compared to just having callbacks which could be more expressive. I think it would be useful to allow people to create new input or output streams with handlers using an API similar to |
@antocuni I would be interested in your opinion on this PR, just from the high level API perspective.
I also don't have a very strong opinion, but I would be +1 to reduce the number of API endpoints this exposes if we can. Also, we really need to document that in the end when Thanks for the explanations @hoodmane! The other thing that is still not very clear to me is what would happen if one sets both |
for more information, see https://pre-commit.ci
They overwrite each other yes. |
Thanks for this work @hoodmane ! LGTM from my side, but I think it would be good to have a second review. |
I think I'll go ahead and merge this since @ryanking13 approved it too and it doesn't seem like @antocuni is going to review. |
The readthedocs build is not flaky as far as I can tell. I can reproduce the doc building failure locally and bisection points to this commit. It's just that RTD has an unfortunate tendency not to show status when it fails as it did in the last commit. |
The RTD is failing because this PR added |
Oh yeah adding |
This adds a carefully designed API for controlling stdin, stdout, and stderr. It changes the default behavior to be a bit more useful, though in doing so introduces some mild backwards incompatibility. In particular:
process.stdin
in node (as before) and raises an error if in browser (not as before).process.stdout
in node (before it called console.log) and calls console.log in browser (as before).process.stderr
in node (before it called console.warn) and calls console.warn in browser (as before).stdin
,stdout
, orstderr
as arguments toloadPyodide
,isatty
of the corresponding stream is set to false.The stdin function is now more flexible: we now correctly handle the case where it returns an ArrayBuffer or ArrayBufferView.
I also added 3 new functions to set streams after Pyodide is loaded which offer additional control:
setStdin({stdin?, error?, isatty = false})
-- Sets the stdin function. The stdin function takes no arguments and should return null, undefined, a string, or a buffer. Sets andisatty(stdin)
toisatty
(by defaultfalse
). If error is true, set stdin to always raise an EIO error when it is read.setStdout({raw?, batched?, isatty = false})
-- If neither raw nor batched is passed, restore default stdout behavior. If rwa is passed, the raw stdout function receives a byte which it should interpret as a utf8 character code. Setsisatty(stdout)
to isatty (by defaultfalse
). If batched is passed but not raw, it sets a batched stdout function. The stdout function receives a string and should do something with it. In this case it ignores isatty and sets isatty(stdout) to false.setStderr({raw?, batched?, isatty = false})
-- same but with stderr.Resolves #3112.
Checklists