-
Notifications
You must be signed in to change notification settings - Fork 1
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
Hook into IPython's display #1
Comments
I did this, but I'd still like to be able to use IPython's stuff for sending the final |
Why is IPython sending an IPython's
Similar to how PyCall does it, we just need to define something like: Base.showable(::MIME"application/vnd.jupyter.widget-view+json", o::PyObject) =
!ispynull(o) && PyCall.hasproperty(o, "_model_id") |
It's not, but hooking into that allows us to not special case widgets. Any object that defines a custom mime type in python should™ just work (this is what I was trying to make possible in my PR to IJulia). So it's not that ipython is sending the messages, but rather, I'd like for IJulia/PyInteract to hook into the way objects are converted to MIME bundles so that we can send that bundle as part of IJulia's execute request. |
It used to be that this was just via Nowadays IPython allows objects to define |
I'm partial to just trying to re-use as much of the existing machinery as possible. For reference, this is what the actual code looks like (assuming that my IJulia PR is merged as is): function IJulia.display_payload(object::PyObject)
# The payload returned is of form [data, metadata].
payload = IJuliaInteractiveShell.instance().display_formatter.format(object)
if payload === nothing || isempty(payload[1])
return nothing
end
# Make sure we keep the `PyObject <...>` printing
payload[1]["text/plain"] = sprint(show, object)
return (data=payload[1], metadata=payload[2])
end No special handling, no dealing with dunder methods. I think the more we stick to this kind of approach, the less weird edge cases we're going to run into. |
The problem with calling A Python package Foo could easily have defined |
We're already depending on IPython though (via ipykernel). I think all of this stuff can be completely orthogonal to PyCall and the way it displays objects. The |
We need to forward
IPython.display.display
to actually send things to the IOPub channel (something in the process is not working right now).The text was updated successfully, but these errors were encountered: