Skip to content

Commit

Permalink
Fix io redirection for Julia 1.7, fixes #986. (#989)
Browse files Browse the repository at this point in the history
  • Loading branch information
rgobbel authored Feb 23, 2021
1 parent 776257f commit cc07f6d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "IJulia"
uuid = "7073ff75-c697-5162-941a-fcdaad2a7d2a"
version = "1.23.1"
version = "1.23.2"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand Down
16 changes: 9 additions & 7 deletions src/stdio.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ Base.displaysize(io::IJuliaStdio) = displaysize(io.io)
Base.unwrapcontext(io::IJuliaStdio) = Base.unwrapcontext(io.io)
Base.setup_stdio(io::IJuliaStdio, readable::Bool) = Base.setup_stdio(io.io.io, readable)

for s in ("stdout", "stderr", "stdin")
f = Symbol("redirect_", s)
sq = QuoteNode(Symbol(s))
@eval function Base.$f(io::IJuliaStdio)
io[:jupyter_stream] != $s && throw(ArgumentError(string("expecting ", $s, " stream")))
Core.eval(Base, Expr(:(=), $sq, io))
return io
if VERSION < v"1.7.0-DEV.254"
for s in ("stdout", "stderr", "stdin")
f = Symbol("redirect_", s)
sq = QuoteNode(Symbol(s))
@eval function Base.$f(io::IJuliaStdio)
io[:jupyter_stream] != $s && throw(ArgumentError(string("expecting ", $s, " stream")))
Core.eval(Base, Expr(:(=), $sq, io))
return io
end
end
end

Expand Down
14 changes: 8 additions & 6 deletions test/stdio.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ using IJulia
flush(io)
seek(io, 0)
@test read(io, String) == "stdout\nprint\n"
@test_throws ArgumentError redirect_stdout(IJulia.IJuliaStdio(io, "stderr"))
@test_throws ArgumentError redirect_stdout(IJulia.IJuliaStdio(io, "stdin"))
@test_throws ArgumentError redirect_stderr(IJulia.IJuliaStdio(io, "stdout"))
@test_throws ArgumentError redirect_stderr(IJulia.IJuliaStdio(io, "stdin"))
@test_throws ArgumentError redirect_stdin(IJulia.IJuliaStdio(io, "stdout"))
@test_throws ArgumentError redirect_stdin(IJulia.IJuliaStdio(io, "stderr"))
if VERSION < v"1.7.0-DEV.254"
@test_throws ArgumentError redirect_stdout(IJulia.IJuliaStdio(io, "stderr"))
@test_throws ArgumentError redirect_stdout(IJulia.IJuliaStdio(io, "stdin"))
@test_throws ArgumentError redirect_stderr(IJulia.IJuliaStdio(io, "stdout"))
@test_throws ArgumentError redirect_stderr(IJulia.IJuliaStdio(io, "stdin"))
@test_throws ArgumentError redirect_stdin(IJulia.IJuliaStdio(io, "stdout"))
@test_throws ArgumentError redirect_stdin(IJulia.IJuliaStdio(io, "stderr"))
end
end

mktemp() do path, io
Expand Down

2 comments on commit cc07f6d

@fredrikekre
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/30720

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.23.2 -m "<description of version>" cc07f6d1f5f13bd15ba9d9c60223121f8b20e8ec
git push origin v1.23.2

Please sign in to comment.