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
allow formatters to specify metadata #3190
Conversation
"""shortcut for returning metadata with shape information, if defined""" | ||
md = {} | ||
if self.width: | ||
md['width'] = self.width |
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.
What are the units of width and height here?
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.
Integer pixels make the most sense, but technically anything HTML allows will work ("2em", etc.)
Previously the display publisher had the ability to publish a metadata dict, but we never used it. As I understand this PR, this does a couple of things:
If this is correct we could use this to allow JS code to declare the name of a browser side handler in the metadata? |
That seems correct. The metadata dict is currently a black box. This simply defines that mime-type keys are themselves black boxes that will be passed to the append_mimetype handlers. So you can still add any further arbitrary interpretations of the metadata dict. |
Let's update the docstrings of the various classes/methods this PR touches to reflect that many return values are now a tuple of data, metadata, etc. Things like |
|
Same with docstring of |
I am wondering if we should change how the |
The docstring and code of |
|
Right now we use |
I'm not fond of the |
docstrings updated |
We could, though the way we have it now will work, since it just uses the measured initial size, which will always be the specified size given with metadata, so it would be a bit redundant. |
Are you sure? From looking at the code, I think the |
Oh, that's even worse - I was thinking of display, which always includes plaintext. publish doesn't for some reason. Why do the publish_foo methods exist? |
Originally, you couldn't publish metadata by calling display for using the On Thu, Apr 25, 2013 at 9:47 PM, Min RK notifications@github.com wrote:
Brian E. Granger |
IOW, display and the top level display objects should be our official On Thu, Apr 25, 2013 at 9:51 PM, Brian Granger ellisonbg@gmail.com wrote:
Brian E. Granger |
we want a metadata dict kwarg on all display types? What should happen if someone specifies width/height as kwargs and via metadata? Or do we want to pass any **kwargs through as metadata? |
Because we need to tightly monitor all metadata attributes, lets set the On Thu, Apr 25, 2013 at 9:56 PM, Min RK notifications@github.com wrote:
Brian E. Granger |
Important question: is this metadata saved in the notebook format? Seems like it should be otherwise when a notebook is reloaded, the metadata will be lost. If it is part of the notebook format, is that not a notebook format change? |
yes, the metadata is saved in the notebook |
formatters can now return either data or (data, metadata) the resulting published dict has both content.data keyed by mime-types,a and content.metadata keyed by mime-types. metadata keys are not necessarily defined, and are generally undefined when they would have no content. This fits fully within the existing message spec.
also consolidate a bunch of duplicate code
adds display(raw=True), which maps directly to publish_display_data on each arg.
So I think this code is ready to merge. The only thing we talked about was updating the message spec/nbformat documentation with information about the metadata. Do you want to do that in a separate PR, or include it here? |
Ah, I updated the IPEP, but forgot to update the actual docs. I'll do that now. I will also add an example or two to the example notebooks. |
OK great! |
docs should be updated |
Merging, great work! |
allow formatters to specify metadata
allow formatters to specify metadata
Part of IPEP 13.
A formatter can now return
(data, metadata)
, in addition to justdata
.A display_data message may now have a key in the content's existing metadata field for each format type.
These keys are not necessarily defined.
The main initial use of this code is to allow images to specify display size,
which should be the missing piece before implementing 2x figures (#2234).
Pinging @piti118, who plans to do that implementation on top of this.