Skip to content

[refactor] GUI: don't directly import Cryo classes in gui.acquisition#3404

Open
pieleric wants to merge 1 commit intodelmic:masterfrom
pieleric:refactor-gui-don-t-directly-import-cryo-classes-in-gui-acquisition
Open

[refactor] GUI: don't directly import Cryo classes in gui.acquisition#3404
pieleric wants to merge 1 commit intodelmic:masterfrom
pieleric:refactor-gui-don-t-directly-import-cryo-classes-in-gui-acquisition

Conversation

@pieleric
Copy link
Copy Markdown
Member

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.

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.
Copilot AI review requested due to automatic review settings March 17, 2026 10:05
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.py by switching to a forward-referenced type annotation for LocalizationTab.

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.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 17, 2026

📝 Walkthrough

Walkthrough

This 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 __init__.py, replace module-qualified imports with direct class imports in tabs, consolidate multi-line imports into single-line statements, and introduce a string-based forward reference annotation for LocalizationTab to break a potential circular dependency. Unused imports (math, popup, create_filename) are removed. No control flow or behavioral modifications occur; this is purely an import restructuring and cleanup effort.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main change: removing direct imports of Cryo classes from the gui.acquisition package to avoid unnecessary dependency loading.
Description check ✅ Passed The description clearly explains the motivation and rationale for the changes, detailing the import chain problem and the solution of requiring explicit imports.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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_tab is 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

📥 Commits

Reviewing files that changed from the base of the PR and between c1b1ff1 and 223ed23.

📒 Files selected for processing (5)
  • src/odemis/gui/cont/acquisition/__init__.py
  • src/odemis/gui/cont/acquisition/cryo_z_localization.py
  • src/odemis/gui/cont/correlation.py
  • src/odemis/gui/cont/tabs/fibsem_tab.py
  • src/odemis/gui/cont/tabs/localization_tab.py
💤 Files with no reviewable changes (1)
  • src/odemis/gui/cont/acquisition/init.py

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.

3 participants