[refactor] GUI: don't directly import Cryo classes in gui.acquisition#3404
Conversation
Having all controllers available in gui.acquisition is handy as it makes the import slightly faster to read, but that also means that any import of gui.acquisition automatically imports all the controllers. The Cryo controllers then imports all the acq.milling, which is quite large, as it imports fibsemOS (if available). So, to avoid importing too much, let the users of the Cryo controllers explicitly import the submodules in gui acquisition. This avoids trying to load (and failing) fibsemOS on the SPARC, FASTEM or viewer.
There was a problem hiding this comment.
Pull request overview
Refactors GUI controller imports to avoid pulling Cryo acquisition/milling dependencies (and fibsemOS import attempts) into non-cryo runtimes when importing odemis.gui.cont.acquisition or correlation-related controllers.
Changes:
- Stop re-exporting Cryo controllers from
odemis.gui.cont.acquisition.__init__and require explicit submodule imports instead. - Update Cryo-related tabs to import Cryo controllers directly from their submodules.
- Remove a transitive import from
correlation.pyby switching to a forward-referenced type annotation forLocalizationTab.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/odemis/gui/cont/tabs/localization_tab.py |
Replace acquisition package import with direct imports of Cryo controllers. |
src/odemis/gui/cont/tabs/fibsem_tab.py |
Replace acquisition package import with direct import of CryoAcquiController. |
src/odemis/gui/cont/correlation.py |
Avoid importing LocalizationTab at module import time via quoted type annotations. |
src/odemis/gui/cont/acquisition/cryo_z_localization.py |
Minor cleanup: remove unused imports and simplify widget import formatting. |
src/odemis/gui/cont/acquisition/__init__.py |
Remove Cryo controller re-exports to keep package import lightweight. |
You can also share your feedback on Copilot code review. Take the survey.
📝 WalkthroughWalkthroughThis pull request refactors import organization and removes re-exported entities across the acquisition and correlation control modules. The changes eliminate public re-exports of CryoAcquiController and CryoZLocalizationController from the acquisition package's 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/odemis/gui/cont/correlation.py (1)
264-264: Redundant type re-annotations on assignment.Once
self.localization_tabis annotated at line 137, these re-annotations on assignment are redundant and contribute to the static analysis warnings. They can be simplified:♻️ Suggested simplification
- self.localization_tab: "LocalizationTab" = self._main_data_model.getTabByName("cryosecom-localization") + self.localization_tab = self._main_data_model.getTabByName("cryosecom-localization")Apply the same change at line 469.
Also applies to: 469-469
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/odemis/gui/cont/correlation.py` at line 264, The assignment to self.localization_tab currently includes a redundant inline type re-annotation (self.localization_tab: "LocalizationTab" = self._main_data_model.getTabByName("cryosecom-localization"); same issue repeats at the other location around line 469); remove the type on the assignment and leave the attribute's original declaration (the annotation at its earlier definition) in place so the code becomes self.localization_tab = self._main_data_model.getTabByName("cryosecom-localization"), keeping getTabByName and the attribute name unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/odemis/gui/cont/correlation.py`:
- Line 137: The string forward reference "LocalizationTab" on the attribute
self.localization_tab should be converted to a proper static-analysis-resolvable
reference by importing the type under a TYPE_CHECKING guard: add "from typing
import TYPE_CHECKING" and inside "if TYPE_CHECKING:" import LocalizationTab from
odemis.gui.cont.tabs.localization_tab, then update the annotation on
self.localization_tab to use LocalizationTab (no quotes); this preserves runtime
import avoidance while satisfying Ruff/F821.
---
Nitpick comments:
In `@src/odemis/gui/cont/correlation.py`:
- Line 264: The assignment to self.localization_tab currently includes a
redundant inline type re-annotation (self.localization_tab: "LocalizationTab" =
self._main_data_model.getTabByName("cryosecom-localization"); same issue repeats
at the other location around line 469); remove the type on the assignment and
leave the attribute's original declaration (the annotation at its earlier
definition) in place so the code becomes self.localization_tab =
self._main_data_model.getTabByName("cryosecom-localization"), keeping
getTabByName and the attribute name unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 56188f9b-1ac0-417b-b7bc-5b66a43707eb
📒 Files selected for processing (5)
src/odemis/gui/cont/acquisition/__init__.pysrc/odemis/gui/cont/acquisition/cryo_z_localization.pysrc/odemis/gui/cont/correlation.pysrc/odemis/gui/cont/tabs/fibsem_tab.pysrc/odemis/gui/cont/tabs/localization_tab.py
💤 Files with no reviewable changes (1)
- src/odemis/gui/cont/acquisition/init.py
Having all controllers available in gui.acquisition is handy as it makes
the import slightly faster to read, but that also means that any import
of gui.acquisition automatically imports all the controllers.
The Cryo controllers then imports all the acq.milling, which is quite
large, as it imports fibsemOS (if available).
So, to avoid importing too much, let the users of the Cryo controllers
explicitly import the submodules in gui acquisition.
This avoids trying to load (and failing) fibsemOS on the SPARC, FASTEM
or viewer.