♻️ Refactor WSIReader.open#1092
Open
shaneahmed wants to merge 8 commits into
Open
Conversation
- Move `WSIReader.open` and all `try_*` functions to `factory.py` - WSIReader then imports lazily `open_wsi` from `factory.py`. - Move all `is_*` functions to `detection.py` - Move `WSIReaderParams` to `types.py`
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #1092 +/- ##
===========================================
+ Coverage 99.88% 99.90% +0.01%
===========================================
Files 86 89 +3
Lines 11661 11687 +26
Branches 1531 1532 +1
===========================================
+ Hits 11648 11676 +28
+ Misses 7 5 -2
Partials 6 6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors WSI reader selection and format-detection logic by extracting WSIReader.open/try_* creation helpers into a dedicated factory.py, and moving is_* detection helpers into detection.py, while introducing a shared WSIReaderParams TypedDict in types.py.
Changes:
- Added
wsireader/factory.pyimplementingopen_wsi,verify_supported_wsi, and thetry_*reader-selection helpers. - Added
wsireader/detection.pyconsolidatingis_*helper functions (including NGFF/Zarr checks and fsspec JSON validation). - Updated
WSIReader.opento lazily import and delegate tofactory.open_wsi, and updated public imports/tests accordingly.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
tiatoolbox/wsicore/wsireader/types.py |
Introduces WSIReaderParams TypedDict for reader-related kwargs. |
tiatoolbox/wsicore/wsireader/factory.py |
New factory module providing open_wsi and try_* helper functions for reader selection. |
tiatoolbox/wsicore/wsireader/detection.py |
New module centralizing WSI-type detection and validation utilities. |
tiatoolbox/wsicore/wsireader/base.py |
Refactors WSIReader.open to call into the factory; removes inlined detection/selection helpers. |
tiatoolbox/wsicore/wsireader/__init__.py |
Updates public imports to pull detection helpers from detection.py. |
tiatoolbox/wsicore/__init__.py |
Moves WSIReaderParams definition to wsireader/types.py and re-exports it. |
tests/test_wsireader.py |
Updates tests to import/use new factory/detection helpers; adds coverage for new edge cases. |
tests/test_tiffreader.py |
Updates TIFF-related tests to call factory.try_tiff and patch new call sites. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+148
to
+150
| _, _, suffixes = utils.misc.split_path_name_ext(input_path) | ||
| last_suffix = suffixes[-1] | ||
|
|
Comment on lines
+237
to
+242
| def try_annotation_store( | ||
| input_path: Path, | ||
| last_suffix: str, | ||
| post_proc: str | callable | None, | ||
| kwargs: Unpack[WSIReaderParams], | ||
| ) -> AnnotationStoreReader | None: |
Comment on lines
+78
to
+81
| try: | ||
| _ = zarr.open(path, **kwargs, mode="r") | ||
| except Exception: # skipcq: PYL-W0703 # noqa: BLE001 | ||
| return False |
Comment on lines
+24
to
25
| from .detection import is_dicom, is_ngff, is_tiled_tiff, is_url, is_zarr | ||
|
|
Comment on lines
39
to
43
| "WSIReader", | ||
| "_handle_tiff_wsi", | ||
| "_handle_virtual_wsi", | ||
| "fix_mangled_url_by_pathlib", | ||
| "is_dicom", | ||
| "is_ngff", |
Comment on lines
+344
to
+346
| def fix_mangled_url_by_pathlib(input_path: str | Path) -> str: | ||
| """Fix URl mangled by Path.""" | ||
| # Fix Mangled URL |
Comment on lines
+97
to
+104
| Args: | ||
| path (Path): | ||
| Path to the file to check. | ||
| min_version (Tuple[int, ...]): | ||
| Minimum version of the NGFF file to be considered valid. | ||
| max_version (Tuple[int, ...]): | ||
| Maximum version of the NGFF file to be considered valid. | ||
|
|
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.
WSIReader.openand alltry_*functions tofactory.pyopen_wsifromfactory.py.is_*functions todetection.pyWSIReaderParamstotypes.pyfactory.py