Support IPython retina display metadata in notebook image outputs#13883
Open
rodrigosf672 wants to merge 1 commit into
Open
Support IPython retina display metadata in notebook image outputs#13883rodrigosf672 wants to merge 1 commit into
IPython retina display metadata in notebook image outputs#13883rodrigosf672 wants to merge 1 commit into
Conversation
Propagate display_data metadata (width/height) from the Jupyter message through the kernel supervisor and cell execution pipeline so notebook images rendered with retina=True display at the correct half-size dimensions. Fixes #8383
|
E2E Tests 🚀 |
IPython retina display metadata in notebook image outputs
Contributor
There was a problem hiding this comment.
Pull request overview
This PR plumbs Jupyter display metadata through the Positron notebook output pipeline so IPython retina image outputs can render with explicit dimensions.
Changes:
- Forwards display metadata from the runtime supervisor into notebook cell output metadata.
- Passes output metadata into image parsing and adds optional image dimensions to parsed output.
- Renders parsed image dimensions on notebook
<img>elements and adds unit coverage for PNG metadata parsing.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
extensions/positron-supervisor/src/RuntimeMessageEmitter.ts |
Includes Jupyter display metadata in emitted runtime output messages. |
src/vs/workbench/contrib/runtimeNotebookKernel/browser/runtimeNotebookCellExecution.ts |
Adds runtime message metadata to notebook cell output metadata. |
src/vs/workbench/contrib/positronNotebook/browser/getOutputContents.ts |
Extracts PNG width/height metadata while parsing outputs. |
src/vs/workbench/contrib/positronNotebook/browser/PositronNotebookCells/IPositronNotebookCell.ts |
Extends parsed image outputs with optional dimensions. |
src/vs/workbench/contrib/positronNotebook/browser/PositronNotebookCells/PositronNotebookCodeCell.ts |
Supplies output metadata to the parser. |
src/vs/workbench/contrib/positronNotebook/browser/notebookCells/NotebookCodeCell.tsx |
Applies parsed dimensions to rendered image elements. |
src/vs/workbench/contrib/positronNotebook/test/browser/notebookOutputUtils.vitest.ts |
Adds tests for PNG parsing with and without retina metadata. |
| outputId: generateNotebookCellOutputId(), | ||
| outputs: outputItems, | ||
| metadata: { outputType, [outputIdKey]: message.output_id, executionCount }, | ||
| metadata: { outputType, [outputIdKey]: message.output_id, executionCount, ...message.metadata }, |
| } | ||
|
|
||
| if (mime === 'image/png') { | ||
| const imgMeta = (metadata?.[mime] ?? metadata) as { width?: number; height?: number } | undefined; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #8383
Summary
display_datametadata (width/height) from Jupyter messages through the kernel supervisor and cell execution pipelineretina=Truenow display at the correct half-size dimensions instead of full pixel sizeWhen IPython's
display(Image("file.png", retina=True))is called, the kernel sends image dimensions metadata ({"image/png": {"width": W, "height": H}}). Previously this metadata was discarded at two points in the pipeline:RuntimeMessageEmitter.onDisplayData()only forwarded transport metadata, andruntimeNotebookCellExecutiondidn't include message metadata in the cell output. Now it flows through to the<img>tag aswidth/heightattributes.Changes
RuntimeMessageEmitter.ts: merge display metadata (data.metadata) into the emitted messageruntimeNotebookCellExecution.ts: spreadmessage.metadatainto cell output metadatagetOutputContents.ts: accept optional metadata param, extractwidth/heightforimage/pngIPositronNotebookCell.ts: add optionalwidth/heightto theParsedOutputimage variantPositronNotebookCodeCell.ts: passoutput.metadatatoparseOutputData()NotebookCodeCell.tsx: renderwidth/heightattributes on the<img>elementTest plan
notebookOutputUtils.vitest.ts(both passing):parses image/png with retina metadata into an image with width and heightparses image/png without metadata into an image with no dimensionsfrom IPython.display import display, Image; display(Image("file.png", retina=True))— image renders at half pixel dimensionsretina=True— image renders at full size (no width/height attributes)@:positron-notebooks @:notebooks @:win @:web