Skip to content

Sphinx-anywidget#9

Open
CSSFrancis wants to merge 7 commits intomainfrom
sphinx-anywidget
Open

Sphinx-anywidget#9
CSSFrancis wants to merge 7 commits intomainfrom
sphinx-anywidget

Conversation

@CSSFrancis
Copy link
Copy Markdown
Owner

This pull request introduces several enhancements and new features focused on improving interactive documentation support, widget communication, and robustness of the plotting library. The most significant addition is the new sphinx_anywidget Sphinx extension, which enables fully interactive figures in documentation using Pyodide, without requiring a server or Jupyter kernel. Additionally, the PR improves the widget–parent page communication bridge, makes colormap handling more robust, and ensures deterministic panel IDs for subplot panels. Minor changes include code comments for Sphinx Gallery compatibility and a new end-to-end test for the Playwright-based thumbnail scraper.

Sphinx extension for interactive documentation:

  • Added the new anyplotlib.sphinx_anywidget Sphinx extension, which enables interactive anywidget-based figures in documentation via Pyodide, provides a custom RST directive (.. anywidget-figure::), and integrates with Sphinx Gallery. This includes automatic wheel building for the target package and seamless asset injection. [1] [2]

Widget–parent page communication improvements:

  • Enhanced the widget HTML/JS bridge in _repr_utils.py to support robust two-way communication between widgets and the parent page using postMessage, including loop-prevention flags, event forwarding, and handling inbound state updates for Pyodide-based interactivity. [1] [2] [3] [4] [5]

Plotting library robustness and determinism:

  • Improved colormap LUT building in figure_plots.py to prefer colorcet but gracefully fall back to matplotlib or a gray ramp if unavailable, making color mapping more robust across environments.
  • Made subplot panel IDs deterministic by deriving them from the panel's position, ensuring stable IDs across runs and after code edits.

Testing and Sphinx Gallery compatibility:

  • Added a quick end-to-end test for the Playwright-based scraper thumbnail functionality in _test_scraper.py.
  • Added # Interactive comments to several example scripts for Sphinx Gallery compatibility. [1] [2] [3] [4] [5]

Event dispatching improvements:

  • Refactored event handling in figure.py to centralize event dispatch logic, allowing both traitlet observers and the Pyodide bridge to process interaction events consistently.

CSSFrancis added 5 commits May 3, 2026 14:01
Adds anyplotlib/sphinx_anywidget/ — a self-contained Sphinx extension that
makes any anywidget.AnyWidget-based figure interactive in documentation
pages via Pyodide, with no server or Jupyter kernel required.
Key changes
-----------
anyplotlib/sphinx_anywidget/
  __init__.py           Sphinx extension entry point; auto-injects JS/CSS,
                        builds wheel at docs-build time, registers directive
  _scraper.py           Generic AnywidgetScraper (replaces ViewerScraper);
                        detects '# Interactive' comment tag to opt-in per block
  _repr_utils.py        Self-contained HTML builder (no anyplotlib dep);
                        uses awi_state/awi_event message protAdds anyplotlib/sphinx_anywidget/ — a self-contained Sphinx extension that
makes any anywidget.AnyWidget-based figure interactive in documentation
pages via Pyodide, with no server or Jupyter kernel required.
Key changes
-----------
anyplotlib/sphinx_anywidget/
  __init__.py           Sphinx extension entry point;?akes any anywidget.AnyWidget-based figure inywidget monkey-patch replaces thpages via Pyodide, with no server or Jupyter kernel required.
Key chanecKey changes
-----------
anyplotlib/sphinx_anywidget/
  _      ----------inanyplotlibivate-btn, awi-static-icon)
any                        builds wheel at docs-build time, registers directf-  _scraper.py           Generic Anywie_fig_id attribute
  - _push() / _push_layout() / _push_widget() always write to traitlets;
    the generic monkey-  _repr_utils.py        Sethe change via
    traitlets.observe(names=All) — no                        uses awi_state/awi_event message protAdds anyplstmakes any anywidget.AnyWidget-based figure interactive in documentation
pages via Pyodide, with no server or Jupyter kernel required.
Keespages via Pyodide, with no server or Jupyter kernel required.
Key channsKey changes
-----------
anyplotlib/sphinx_anywidget/
  __ini_g----------f
anyplotlibtm  __init__.py           SphitKey chanecKey changes
-----------
anyplotlib/sphinx_anywidget/
  _      ----------inanyplotlibivate-btn, awi-static-icon)
any                        builds wheel at docs-build time, registers to-------raits directly
anyplotlib b  _      ----------inanyplogeany                        builds wheel at docs-build timta  - _push() / _push_layout() / _push_widget() always write to traitlets;
    the generic monkey-  _repr_utils.py ton
  - Update mock r    the generic monkey-  _repr_(_patched_init pattern)
Usage in other pro    traitlets.observe(names=All) — no                       nxpages via Pyodide, with no server or Jupyter kernel required.
Keespages via Pyodide, with no server or Jupyter kernel required.
Key channsKey changes
-----------
anyplotlib/sphinxteracKeespages via Pyodide, with no server or Jupyter kerngit log --oneline -3
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 3, 2026

Codecov Report

❌ Patch coverage is 5.23416% with 344 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.44%. Comparing base (ba0db6e) to head (e997da2).

Files with missing lines Patch % Lines
anyplotlib/sphinx_anywidget/_scraper.py 0.00% 128 Missing ⚠️
anyplotlib/sphinx_anywidget/_directive.py 0.00% 73 Missing ⚠️
anyplotlib/sphinx_anywidget/_repr_utils.py 0.00% 57 Missing ⚠️
anyplotlib/sphinx_anywidget/__init__.py 0.00% 53 Missing ⚠️
anyplotlib/sphinx_anywidget/_wheel_builder.py 0.00% 22 Missing ⚠️
anyplotlib/figure_plots.py 59.25% 11 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main       #9       +/-   ##
===========================================
- Coverage   87.79%   74.44%   -13.36%     
===========================================
  Files           7       12        +5     
  Lines        1901     2250      +349     
===========================================
+ Hits         1669     1675        +6     
- Misses        232      575      +343     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@CSSFrancis
Copy link
Copy Markdown
Owner Author

@ericpre

Long time coming.... But live responsive interactive documentation should be possible with this... I need to set up github to host docs from PRs still but once that is up it should be really nice for demoing a feature, writing documentation etc.

Screen.Recording.2026-05-03.at.2.30.58.PM.mov

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.

2 participants