Skip to content

Add Verso notebook support inside DotnetMatplotlib.Interactive (#1) - #2

Merged
gnrkr789 merged 3 commits into
mainfrom
1-add-support-of-verso-notebooks
Jun 27, 2026
Merged

Add Verso notebook support inside DotnetMatplotlib.Interactive (#1)#2
gnrkr789 merged 3 commits into
mainfrom
1-add-support-of-verso-notebooks

Conversation

@gnrkr789

Copy link
Copy Markdown
Owner

.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.

.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.
@gnrkr789 gnrkr789 self-assigned this Jun 27, 2026
Copilot AI review requested due to automatic review settings June 27, 2026 15:08
@gnrkr789 gnrkr789 linked an issue Jun 27, 2026 that may be closed by this pull request

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 emits image/svg+xml for Figure and Plt.
  • 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.

Comment thread src/Matplotlib.Interactive/Verso.fs Outdated
match value with
| :? Figure as fig -> FigureCanvas(fig).RenderToSvg()
| :? Plt as plt -> plt.ToSvg()
| _ -> "" // unreachable: the host only calls this after CanFormat
gnrkr789 added 2 commits June 28, 2026 00:15
…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.
@gnrkr789
gnrkr789 merged commit 097dc37 into main Jun 27, 2026
2 checks passed
@gnrkr789
gnrkr789 deleted the 1-add-support-of-verso-notebooks branch June 27, 2026 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support of Verso notebooks

2 participants