fix: use qtpy instead of importing PyQt5 directly - #40
Open
hongquanli wants to merge 2 commits into
Open
hongquanli wants to merge 2 commits into
hongquanli wants to merge 2 commits into
Conversation
Squid runs this viewer embedded in its own process, which is PyQt6-only since the napari 0.7 migration, so `from PyQt5...` raised ImportError and the NDViewer tab failed to load. Installing PyQt5 alongside is not an option: two Qt bindings in one environment break napari/vispy OpenGL rendering. qtpy promotes unscoped enums under PyQt6, so Qt.AlignCenter-style access is unchanged; only pyqtSignal needed renaming to Signal. The declared dependency is now qtpy rather than a concrete binding, which the host application supplies.
qtpy resolves a binding at import time and raises QtBindingsNotFoundError when none is installed, so replacing the pyqt5 dependency with qtpy alone broke every standalone use: CI collected 14 import errors, and the simulate_* scripts would fail the same way. Embedded in Squid the host process already supplies PyQt6, which is why a concrete binding must not be a hard dependency here -- a second binding in that environment breaks napari/vispy OpenGL rendering. So it is an extra, `pip install .[pyqt6]`, mirroring napari[pyqt6], and environment.yml (used by CI and for standalone work) installs PyQt6 explicitly.
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.
Problem
ndviewer_lightimports PyQt5 directly. Squid embeds this viewer in its own process, and since the napari 0.7 migration (Cephla-Lab/Squid#622) that process is PyQt6-only, so every import fails:The NDViewer tab then silently degrades to
NDViewer tab unavailable: ndviewer_light module not installed(gui_hcs.py:1226).Installing PyQt5 alongside is not an option — two Qt bindings in one environment break napari/vispy OpenGL rendering, which
setup_22.04.shcalls out explicitly:This is not platform-specific: anyone following
setup_22.04.shon Ubuntu gets a PyQt6-only environment and hits it identically.Change
Import through
qtpyand let the host application supply the binding.ndviewer_light/core.py,simulate_push_acquisition.py,simulate_zarr_acquisition.py,tests/test_3d_visualization.py—PyQt5.*→qtpy.*pyproject.toml/environment.yml— declareqtpyinstead ofpyqt5Two details worth noting:
Signal, notpyqtSignal, so the two signal declarations incore.pywere renamed accordingly.Qt.AlignCenter-style access needed no changes — this is why the diff is as small as it is.Verification
Under Python 3.12 / PyQt6 6.11.0 / napari 0.7.1:
import ndviewer_lightsucceeds withqtpy.API_NAME == "PyQt6"test_widgets.pygoes from 4 failures to 158 passedRequires
tensorstoreat import time, which Squid's setup script installs as of Cephla-Lab/Squid#622.