Add Verso notebook support inside DotnetMatplotlib.Interactive (#1) - #2
Merged
Conversation
.NET Interactive / Polyglot Notebooks is being retired, so add support for its successor Verso (https://versonotebooks.com/), requested in #1. Rather than a new package, the Verso formatter ships inside the existing DotnetMatplotlib.Interactive package: MatplotlibFormatter is a [VersoExtension]-marked IDataFormatter that renders a Figure or Plt returned from a cell as inline SVG (image/svg+xml). The Verso host discovers it automatically by scanning for the attribute -- no register() call, unlike the .NET Interactive formatters in the same package. - src/Matplotlib.Interactive: add Verso.fs; reference Verso.Abstractions 1.0.22 (targets net10.0); update the package Description/tags. - tests: 5 VersoTests (svg mime/content, CanFormat gating, the [VersoExtension] marker). Full suite 166 passing. - README / nuget README / PORTING / CHANGELOG document Verso as the successor path, shipped in the Interactive package.
There was a problem hiding this comment.
Pull request overview
This PR adds first-class Verso notebook support to the existing DotnetMatplotlib.Interactive package by shipping a [VersoExtension]-discoverable IDataFormatter that renders returned Figure/Plt values as inline SVG output.
Changes:
- Add
Matplotlib.Verso.MatplotlibFormatter(IDataFormatter/IExtension) that emitsimage/svg+xmlforFigureandPlt. - Add a dedicated Verso test suite and wire it into the test project.
- Update README / NuGet README / PORTING / CHANGELOG to document Verso as the successor path and clarify discovery vs registration behavior.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/Matplotlib.Tests/VersoTests.fs | Adds unit tests validating Verso formatter discoverability and SVG output. |
| tests/Matplotlib.Tests/Matplotlib.Tests.fsproj | Includes the new Verso test file in the test build. |
| src/Matplotlib.Interactive/Verso.fs | Introduces the Verso IDataFormatter/IExtension implementation for SVG rendering. |
| src/Matplotlib.Interactive/Matplotlib.Interactive.fsproj | Adds Verso.fs compilation and references Verso.Abstractions. |
| README.md | Documents how to use the Interactive package in Verso (and legacy .NET Interactive). |
| PORTING.md | Adds a new entry describing the Verso formatter integration. |
| nuget/README.md | Updates NuGet package README notebook guidance for Verso + legacy .NET Interactive. |
| CHANGELOG.md | Records Verso notebook support under Unreleased additions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| match value with | ||
| | :? Figure as fig -> FigureCanvas(fig).RenderToSvg() | ||
| | :? Plt as plt -> plt.ToSvg() | ||
| | _ -> "" // unreachable: the host only calls this after CanFormat |
…ation Use Verso's own Verso.Testing.Stubs.StubFormatterContext (the context the host passes to formatters) instead of a null, matching Verso's documented testing pattern. Add a test that replicates the host's discovery pipeline against the shipped assembly: scan for [VersoExtension] types implementing IDataFormatter, construct via Activator.CreateInstance (as the host does), then format a real figure and assert image/svg+xml output.
Verso loads each extension into its own collectible AssemblyLoadContext and shares only Verso.Abstractions with the host. A live `verso run` showed the formatter never claimed a returned Plt: the host pre-filters with SupportedTypes.Any(t.IsInstanceOfType(value)), and the kernel's Plt is a different CLR type than this assembly's, so the typed match failed and the built-in object-tree formatter rendered the value instead. Fix: advertise typeof<obj> (the only type identity shared across contexts) so the pre-filter passes, gate by type name in CanFormat, and render via reflection (Plt.ToSvg(); a bare Figure through FigureCanvas loaded from the value's own context) instead of a cross-context cast. Verified against the real Verso.Cli host (verso run --extensions): a cell returning a Plt now emits image/svg+xml (a 5.4 KB SVG with the plotted path and title), cell status Success. In-process tests updated for the obj catch-all + name-based gating; full suite 166 passing.
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.
.NET Interactive / Polyglot Notebooks is being retired, so add support for its successor Verso (https://versonotebooks.com/), requested in #1.
Rather than a new package, the Verso formatter ships inside the existing DotnetMatplotlib.Interactive package: MatplotlibFormatter is a [VersoExtension]-marked IDataFormatter that renders a Figure or Plt returned from a cell as inline SVG (image/svg+xml). The Verso host discovers it automatically by scanning for the attribute -- no register() call, unlike the .NET Interactive formatters in the same package.