Skip to content

Move in-line imports to top of files#542

Merged
nvaytet merged 7 commits intoscipp:mainfrom
MridulS:imports_lazy
Mar 11, 2026
Merged

Move in-line imports to top of files#542
nvaytet merged 7 commits intoscipp:mainfrom
MridulS:imports_lazy

Conversation

@MridulS
Copy link
Member

@MridulS MridulS commented Mar 6, 2026

Since lazy_loader was introduced in #405, modules are lazily loaded so deferred imports to avoid hard dependencies are no longer needed.

Closes #541

Did some rudimentary tests on import times, didn't see much affect as expected.

Since lazy_loader was introduced in scipp#405, modules are lazily loaded
so deferred imports to avoid hard dependencies are no longer needed.

Closes scipp#541

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
import warnings
from typing import Literal

import ipywidgets
Copy link
Member

Choose a reason for hiding this comment

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

Can you abbreviate ipywidgets to ipw?
That's what we do everywhere else in the code.

@@ -154,12 +155,6 @@ def _get_points_info(artist, figure):


def _make_points(**kwargs):
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, does this mean that we can do away with the entire function _make_points (and the like)?
The comment clearly states it's to avoid issues with dependency import?

"""
Convert the underlying Matplotlib figure to an image widget from ``ipywidgets``.
"""
from ipywidgets import Image
Copy link
Member

Choose a reason for hiding this comment

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

This import is a little different.
We still want to be able to use the matplotlib-based canvas without ipywidgets (to make static figures).
If we request a Canvas, ipywidgets would now be a hard-dependency, even with the lazy_loader.
I'll revert this part.

from matplotlib.figure import Figure as MplFigure

from ...graphics import BaseFig
from ...widgets import HBar, VBar, make_toolbar_canvas2d
Copy link
Member

Choose a reason for hiding this comment

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

Same as above. We should still be able to make static mpl figures without ipywidgets.
I wonder why this was not picked up by CI?

I thought we had tests running with only minimal deps?

Copy link
Member

Choose a reason for hiding this comment

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

Oh, see #544 😞

"""
Convert the colorbar into a widget for use with other ``ipywidgets``.
"""
import ipywidgets as ipw
Copy link
Member

Choose a reason for hiding this comment

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

This one should also be reverted.

nvaytet and others added 2 commits March 11, 2026 10:45
Co-authored-by: Neil Vaytet <39047984+nvaytet@users.noreply.github.com>
@nvaytet nvaytet merged commit 08772af into scipp:main Mar 11, 2026
6 checks passed
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.

Move all in-line imports to the top

2 participants