Skip to content

Commit

Permalink
Merge pull request #1138 from halleysfifthinc/messaging-updates
Browse files Browse the repository at this point in the history
Jupyter messaging updates/correctness
  • Loading branch information
JamesWrigley authored Jan 29, 2025
2 parents 2164bfc + 57df15d commit 4a5d51b
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ JSON = "0.18,0.19,0.20,0.21,1"
MbedTLS = "0.5,0.6,0.7,1"
SoftGlobalScope = "1"
ZMQ = "1.3"
julia = "1.6"
julia = "1.10"
4 changes: 2 additions & 2 deletions src/IJulia.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export notebook, jupyterlab, installkernel
using ZMQ, JSON, SoftGlobalScope
import Base.invokelatest
import Dates
using Dates: now
using Dates: now, format, UTC, ISODateTimeFormat
import Random
using Base64: Base64EncodePipe
import REPL
Expand Down Expand Up @@ -285,7 +285,7 @@ function clear_output(wait=false)
# flush pending stdio
flush_all()
empty!(displayqueue) # discard pending display requests
send_ipython(publish[], msg_reply(execute_msg::Msg, "clear_output",
send_ipython(publish[], msg_pub(execute_msg::Msg, "clear_output",
Dict("wait" => wait)))
stdio_bytes[] = 0 # reset output throttling
end
Expand Down
2 changes: 1 addition & 1 deletion src/comm_manager.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function comm_info_request(sock, msg)
end
content = Dict(:comms => _comms)

send_ipython(IJulia.publish[],
send_ipython(sock,
msg_reply(msg, "comm_info_reply", content))
end

Expand Down
1 change: 1 addition & 0 deletions src/display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ register_jsonmime(x::AbstractVector{<:MIME}) = push!(ijulia_jsonmime_types, Vect
# return a String=>Any dictionary to attach as metadata
# in Jupyter display_data and pyout messages
metadata(x) = Dict()
transient(x) = Dict()

"""
Generate the preferred MIME representation of x.
Expand Down
8 changes: 4 additions & 4 deletions src/handlers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,11 @@ function complete_request(socket, msg)
end

function kernel_info_request(socket, msg)
send_ipython(requests[],
send_ipython(socket,
msg_reply(msg, "kernel_info_reply",
Dict("protocol_version" => "5.0",
Dict("protocol_version" => "5.4",
"implementation" => "ijulia",
# TODO: "implementation_version" => IJulia version string from Pkg
"implementation_version" => pkgversion(@__MODULE__),
"language_info" =>
Dict("name" => "julia",
"version" =>
Expand Down Expand Up @@ -274,7 +274,7 @@ end

function interrupt_request(socket, msg)
@async Base.throwto(requests_task[], InterruptException())
send_ipython(requests[], msg_reply(msg, "interrupt_reply", Dict()))
send_ipython(socket, msg_reply(msg, "interrupt_reply", Dict()))
end

function unknown_request(socket, msg)
Expand Down
3 changes: 3 additions & 0 deletions src/inline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ for mime in ipy_mime
msg_pub(execute_msg, "display_data",
Dict(
"metadata" => metadata(x), # optional
"transient" => transient(x), # optional
"data" => Dict($mime => limitstringmime(MIME($mime), x)))))
end
displayable(d::InlineDisplay, ::MIME{Symbol($mime)}) = true
Expand All @@ -87,6 +88,7 @@ function display(d::InlineDisplay, M::MIME, x)
send_ipython(publish[],
msg_pub(execute_msg, "display_data",
Dict("metadata" => metadata(x), # optional
"transient" => transient(x), # optional
"data" => d)))
end

Expand All @@ -98,6 +100,7 @@ function display(d::InlineDisplay, x)
send_ipython(publish[],
msg_pub(execute_msg, "display_data",
Dict("metadata" => metadata(x), # optional
"transient" => transient(x), # optional
"data" => display_dict(x))))
end

Expand Down
6 changes: 3 additions & 3 deletions src/msg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ end
msg_header(m::Msg, msg_type::String) = Dict("msg_id" => uuid4(),
"username" => m.header["username"],
"session" => m.header["session"],
"date" => now(),
"date" => format(now(UTC), ISODateTimeFormat)*"Z",
"msg_type" => msg_type,
"version" => "5.3")
"version" => "5.4")

# PUB/broadcast messages use the msg_type as the ident, except for
# stream messages which use the stream name (e.g. "stdout").
Expand All @@ -32,7 +32,7 @@ msg_pub(m::Msg, msg_type, content, metadata=Dict{String,Any}()) =
msg_header(m, msg_type), content, m.header, metadata)

msg_reply(m::Msg, msg_type, content, metadata=Dict{String,Any}()) =
Msg(m.idents, msg_header(m, msg_type), content, m.header, metadata)
Msg(m.idents, msg_header(m, msg_type), merge(Dict("status" => "ok"), content), m.header, metadata)

function show(io::IO, msg::Msg)
print(io, "IPython Msg [ idents ")
Expand Down

0 comments on commit 4a5d51b

Please sign in to comment.