Skip to content

WIP: use scenex#276

Draft
gselzer wants to merge 23 commits into
pyapp-kit:mainfrom
gselzer:scenex-v2
Draft

WIP: use scenex#276
gselzer wants to merge 23 commits into
pyapp-kit:mainfrom
gselzer:scenex-v2

Conversation

@gselzer

@gselzer gselzer commented May 4, 2026

Copy link
Copy Markdown
Collaborator

Overview

This PR aims to replace the references to multiple canvas backends (vispy, pygfx) with a single implementation against scenex models. It's a large change, deserving lots of review and scrutiny.

Reasoning

  1. One canvas implementation The flexibility ndv offers users presents significant effort for ndv developers who want to enable a feature across both canvas implementations. Both src/ndv/views/_vispy and src/ndv/views/_pygfx have thousands of lines of code and separate test bases. As this PR shows, adopting scenex results in far fewer raw lines of code to maintain.

  2. Robust scene models Adding more functionality (including the ability to display multiple datasets, multiscale data as suggested in multiscale chunked rendering #275, orthoviews, etc.) will require knowledge of the scenegraph state. There are already bits and pieces of this in ndv (e.g. ImageHandle, RectangularROIHandle), but scenex exists for this purpose.

Implementation Goals

The primary goal of this PR is to condense down to a single canvas implementation, removing dependencies on vispy and pygfx in favor of dependencies of scenex, while maintaining the same public API, and all (excluding tests aimed at removed behavior) tests.

@tlambert03 your review is always welcome, but might be good to wait a little longer, as I fear that despite passing tests on my machine this PR will show me that there are many more things to clean up!

@codecov

codecov Bot commented May 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.48737% with 91 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.58%. Comparing base (1dc1a8f) to head (ed18fc8).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/ndv/views/_histogram.py 89.90% 32 Missing ⚠️
src/ndv/views/_shared_histogram.py 92.34% 29 Missing ⚠️
src/ndv/views/_data_canvas.py 93.24% 10 Missing ⚠️
src/ndv/controllers/_array_viewer.py 91.11% 8 Missing ⚠️
src/ndv/controllers/_channel_controller.py 82.22% 8 Missing ⚠️
src/ndv/views/_app.py 87.50% 1 Missing ⚠️
src/ndv/views/_jupyter/_array_view.py 90.00% 1 Missing ⚠️
src/ndv/views/_qt/_array_view.py 80.00% 1 Missing ⚠️
src/ndv/views/_util.py 97.82% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #276      +/-   ##
==========================================
+ Coverage   85.38%   88.58%   +3.20%     
==========================================
  Files          53       42      -11     
  Lines        7192     4942    -2250     
==========================================
- Hits         6141     4378    -1763     
+ Misses       1051      564     -487     

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

gselzer added 2 commits May 4, 2026 15:40
Since we aren't running within a notebook, vispy will try to use glfw
over jupyter unless we force jupyter with the environment variable. This
is the same thing we do in scenex
Needed to get SignalGroupDesciptor.connect_child_events
gselzer added 8 commits May 11, 2026 15:18
This avoids some scenex errors from casting very large values into
32-bit floats
Will probably move them to a different file later
The few functions that still have use have been moved to
src/ndv/views/_util
Just makes for an easier diff
mock_highlight.assert_called_with({})


# ---------- Visual behavior tests ----------

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Noting that these tests were moved over from tests/views/_vispy/test_shared_histogram.py

@@ -1,279 +0,0 @@
"""Tests for VispySharedHistogramCanvas visual behavior."""

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

These tests were moved to tests/test_shared_histogram.py

@@ -1,168 +0,0 @@
from __future__ import annotations

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is really a scenex concern, see how these things are tested e.g. here

@@ -1,163 +0,0 @@
from __future__ import annotations

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

These tests were moved to test/test_histogram.py

gselzer added 3 commits May 29, 2026 15:49
"""Whether to use %gui magic when running in IPython. Default True."""


class NDVApp:

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Note that it would be nice to just get rid of this class, however it's public API

from ._view_base import Viewable

__all__ = [
"ArrayCanvas",

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Just noting that there's lots of public API here being deleted already

Comment thread src/ndv/views/__init__.py
Comment on lines -22 to 21
"CanvasBackend",
"GuiFrontend",
"call_later",
"get_array_canvas_class",
"get_array_view_class",

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

More public API being deleted

Comment thread src/ndv/views/_app.py
@@ -1 +1 @@
from __future__ import annotations

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is another file ripe for pruning.

@gselzer gselzer marked this pull request as ready for review May 29, 2026 22:03
@gselzer gselzer marked this pull request as draft May 29, 2026 22:23
@gselzer

gselzer commented May 29, 2026

Copy link
Copy Markdown
Collaborator Author

@tlambert03 I think I'm getting happier with how this is looking, and would be interested in your initial thoughts here. As I mentioned above, this is a rather large amount of changing code, and it would need a release of scenex before merge. More than anything else, I'm interested in your thoughts about the effects to the project structure, including:

  • The removal of src/ndv/views/_vispy and src/ndv/views/_pygfx, in favor of scenex models in src/ndv/views
  • The removal of src/ndv/views/bases/_graphics, and the slimming down of src/ndv/views/bases.
  • The slimming down of src/ndv/views/_qt et al - there's actually probably more we could trim here if we wanted.
  • The consolidation of several tests.

Despite all of that removal, I think all ndv features are fully functional (let me know if any testing you do uncovers anything I missed).

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.

1 participant