Skip to content

Make from skimage2.subpackage import X work - #8310

Merged
stefanv merged 4 commits into
scikit-image:mainfrom
stefanv:make-skimage2-submodule-imports-work
Sep 3, 2026
Merged

stefanv merged 4 commits into
scikit-image:mainfrom
stefanv:make-skimage2-submodule-imports-work

Conversation

@stefanv

@stefanv stefanv commented Sep 1, 2026 •

Copy link
Copy Markdown
Member

This is done by adding a simple shim for each submodule that forwards to _skimage2.

To make things consistent, I also added lazy-loading for _skimage2.io and _skimage2.filters.rank, which were still eager.

Assisted-by: claude-code:claude-opus-5

These were the only subpackages still importing their attributes
eagerly.

Some special handling is needed for `reset_plugins()`, which is called
eagerly upon module import.

Assisted-by: claude-code:claude-opus-5
Unlike `from skimage2 import filters; filters.X`, `from
skimage2.filters import X` is resolved directly by the import
machinery, and never reaches the module `__getattr__`.

Add a shim for each subpackage, which forwards to `_skimage2`,
which restores the ability to import from the subpackage directly.

Assisted-by: claude-code:claude-opus-5
@greptile-apps

greptile-apps Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "Mirror `_skimage2` subpackages under `sk..." | Re-trigger Greptile

@stefanv

stefanv commented Sep 1, 2026 •

Copy link
Copy Markdown
Member Author

This is an alternative approach to #8291

It adds more files, but it's pretty straightforward what those files do.

@stefanv

stefanv commented Sep 1, 2026

Copy link
Copy Markdown
Member Author

Community call: add test to ensure _skimage2 and skimage2 structures match.

@greptile-apps

greptile-apps Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Reviews (2): Last reviewed commit: "Add test to ensure _skimage2 and skimage..." | Re-trigger Greptile

@blink1073

Copy link
Copy Markdown
Contributor
PARALLEL FAILED tests/skimage2/test_skimage2.py::test_skimage2_modules_match - Failed: DID NOT WARN. No warnings of type (<class '_skimage2._shared._warnings.ExperimentalAPIWarning'>,) were emitted.

Maybe that path got mangled here?

@stefanv

stefanv commented Sep 2, 2026

Copy link
Copy Markdown
Member Author

Interesting; is there a reason the warning wouldn't pop up in all threads?

@blink1073

Copy link
Copy Markdown
Contributor

There is a race condition because pytest.warn is not thread safe. I think the test needs to run in a subprocess like test_import_skimage2_warning does.

@stefanv

stefanv commented Sep 2, 2026

Copy link
Copy Markdown
Member Author

Test only needs to run once, on a single platform, so I'll just mark it as thread-unsafe.

@greptile-apps

greptile-apps Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Reviews (3): Last reviewed commit: "Mark module comparison test thread unsaf..." | Re-trigger Greptile

@stefanv

stefanv commented Sep 3, 2026

Copy link
Copy Markdown
Member Author

OK, should be good to go now.

@blink1073 blink1073 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@stefanv
stefanv merged commit 457ef06 into scikit-image:main Sep 3, 2026
31 of 32 checks passed
@stefanv stefanv added this to the 0.27 milestone Sep 3, 2026
ravikumar266 pushed a commit to ravikumar266/scikit-image that referenced this pull request Sep 10, 2026
blink1073 added a commit to blink1073/scikit-image that referenced this pull request Sep 13, 2026
Merging upstream main (which includes scikit-image#8310: physical skimage2 sub-package
shims) makes skimage2.data a distinct shim module, not the same module as
_skimage2.data. The test asserted module identity, which now fails in CI.
Assert instead that the shim forwards to the same objects and exposes the
same __all__.
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.

2 participants