Skip to content
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

Set IOContext for redirected stdout/stderr #2824

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

danielwe
Copy link

Fixes #2823

No tests yet

Copy link
Contributor

Try this Pull Request!

Open Julia and type:

julia> import Pkg
julia> Pkg.activate(temp=true)
julia> Pkg.add(url="https://github.com/danielwe/Pluto.jl", rev="stdoutiocontext")
julia> using Pluto

Check that each IOContext property is transferred to `stdout` and
`stderr` as seen from inside a notebook
@danielwe
Copy link
Author

Tests added, loosely following the pattern in test/Logging.jl. The idea is to verify that every IOContext property set in PlutoRunner.default_stdout_iocontext is visible on stdout and stderr inside a notebook. (I included stderr because PlutoRunner sends both streams to the same pipe.) Let me know if this should be done differently.

@fonsp
Copy link
Owner

fonsp commented Feb 26, 2024

Thanks! Can you take a look at #2727 and try to find a solution that works for both use cases?

@danielwe
Copy link
Author

How about like this?

@fonsp
Copy link
Owner

fonsp commented Feb 27, 2024

Nice! This seems to match the REPL:

julia> IOContext(stdout).dict
Base.ImmutableDict{Symbol, Any} with 1 entry:
  :color => true

julia> struct ShowMyIO end

julia> Base.show(io::IO, m::MIME"text/plain", s::ShowMyIO) = @info "s" IOContext(io).dict

julia> ShowMyIO()
┌ Info: s
│   (IOContext(io)).dict =
│    Base.ImmutableDict{Symbol, Any} with 4 entries:
│      :module                => Main
│      :limit                 => true
│      :last_shown_line_infos => Tuple{String, Int64}[]
└      :color                 => true

@fonsp
Copy link
Owner

fonsp commented Feb 27, 2024

Could you write the tests in a more end-to-end style? Right now the test is very exact for the question: "did the IO context get set properly"? What I would prefer to test is whether the two issues are fixed:

  • Does printstyled work?
  • Does show(bigarray) and show(stdout, bigarray) and show(stdout, "text/plain", bigarray) show the full array contents? (e.g. check if the middle element occurs in the string)
  • Does display(bigarray) limit the display?

The benefit of an end-to-end test is:

  • We are free to make changes to the implementation in the future, without having to also change our tests.
  • We can later make (seemingly unrelated) changes somewhere else in the stdout display mechanism, with the guarantee that these two issues will remain fixed.

It would also be nice if the tests are added to the existing notebook in test/Logging.jl, this makes the tests run faster because no new process needs to be started.

You can ignore the GitHub Action test failures on Julia nightly, that's being worked on in another PR

@fonsp
Copy link
Owner

fonsp commented Feb 27, 2024

PS Thanks again! Nice implementation :)

@fonsp
Copy link
Owner

fonsp commented Mar 13, 2024

@danielwe Hey! Do you have time to take a look at the tests?

@danielwe
Copy link
Author

Thanks for the feedback! I'm rather strapped for time at the moment. I can probably look at it next week, but if someone wants to adopt this to get it across the finish line sooner, feel free!

@fonsp fonsp marked this pull request as draft March 26, 2024 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IOContext not properly set for stdout, disables ANSI colors
2 participants