Skip to content

Commit 6b347af

Browse files
authored
huge diff: refactor to include utilities container and more settings (#35)
xref: ndev-kit/napari-ndev#210 1. Rip out Utilities Container from napari-ndev 2. Move helpers from napari-ndev to here <- this needs refactored out completely later 3. Update settings 4. update some pyproject config / pre-commit to fix things 5. lazy imports to improve import time (2.5s to 15ms, but nImage still pulls in BioImage which is ~2s) 6. fix and add tests, but nothing is "broken" re: legacy code ## Copilot explanation This pull request introduces several improvements and updates across the codebase, focusing on standardizing configuration naming, expanding settings for export functionality, enhancing dependency management, and adding new utility functions. The changes also improve documentation and developer experience. ### Configuration and Settings Standardization * Renamed all references of `ndevio_Reader` to `ndevio_reader` in settings, code, and documentation for consistency and clarity. This affects YAML files, code logic, and markdown documentation. [[1]](diffhunk://#diff-a54ff182c7e8acf56acfd6e4b9c3ff41e2c41a31c9b211b2deb9df75d9a478f9L98-R98) [[2]](diffhunk://#diff-a54ff182c7e8acf56acfd6e4b9c3ff41e2c41a31c9b211b2deb9df75d9a478f9L285-R285) [[3]](diffhunk://#diff-a54ff182c7e8acf56acfd6e4b9c3ff41e2c41a31c9b211b2deb9df75d9a478f9L311-R311) [[4]](diffhunk://#diff-a54ff182c7e8acf56acfd6e4b9c3ff41e2c41a31c9b211b2deb9df75d9a478f9L565-R565) [[5]](diffhunk://#diff-a1495b29f6e07c8278a427f1ad3f4b1033da9353d263c050f0c8d9ac1b2aeebdL54-R60) [[6]](diffhunk://#diff-a1495b29f6e07c8278a427f1ad3f4b1033da9353d263c050f0c8d9ac1b2aeebdL81-R81) [[7]](diffhunk://#diff-11c9170a9cc22a07c8e3347c1210ae7bfb99877cba412ab3d5d79f7c691c9f09L1-R1) [[8]](diffhunk://#diff-11c9170a9cc22a07c8e3347c1210ae7bfb99877cba412ab3d5d79f7c691c9f09R29-R48) [[9]](diffhunk://#diff-e483cf7e2129edce2bdf6c16f9e6bb60e0716ee89b8d788206109cdd6d782c3fL37-R35) [[10]](diffhunk://#diff-e483cf7e2129edce2bdf6c16f9e6bb60e0716ee89b8d788206109cdd6d782c3fL62-R61) [[11]](diffhunk://#diff-e483cf7e2129edce2bdf6c16f9e6bb60e0716ee89b8d788206109cdd6d782c3fL71-R70) [[12]](diffhunk://#diff-e483cf7e2129edce2bdf6c16f9e6bb60e0716ee89b8d788206109cdd6d782c3fL277-R278) * Added new export-related settings under `ndevio_export` to `ndev_settings.yaml`, enabling control over canvas scaling, size, and override behavior for exported figures and screenshots. ### Dependency and Environment Updates * Updated dependencies in `pyproject.toml`: pinned `ndev-settings` to version `>=0.4.0`, added new packages (`napari`, `nbatch`, `natsort`, `magicgui`, `magic-class`), and included `bioio-czi` for development/testing. Also set a minimum coverage threshold for tests. [[1]](diffhunk://#diff-50c86b7ed8ac2cf95bd48334961bf0530cdc77b5a56f852c5c61b89d735fd711L31-R44) [[2]](diffhunk://#diff-50c86b7ed8ac2cf95bd48334961bf0530cdc77b5a56f852c5c61b89d735fd711R60) [[3]](diffhunk://#diff-50c86b7ed8ac2cf95bd48334961bf0530cdc77b5a56f852c5c61b89d735fd711R91-R93) * Modified `.pre-commit-config.yaml` to exclude `src/ndevio/ndev_settings.yaml` from YAML syntax checks and updated the `ndev-settings` hook to use version `0.4.0`. [[1]](diffhunk://#diff-63a9c44a44acf85fea213a857769990937107cf072831e1a26808cfde9d096b9R10-R11) [[2]](diffhunk://#diff-63a9c44a44acf85fea213a857769990937107cf072831e1a26808cfde9d096b9L23-R25) ### Utilities and API Enhancements * Added a new `helpers.py` module with utility functions for file handling and image processing, such as directory scanning, channel name extraction, dimension order calculation, ID string creation, missing file checking, and string elision. * Updated `__init__.py` to support lazy loading of `nImage` and expose the new `helpers` module in the public API. ### Documentation and Developer Experience * Improved documentation in `AGENTS.md` to reflect configuration changes and updated installation instructions to use the correct `uv pip` command for development dependencies. [[1]](diffhunk://#diff-a54ff182c7e8acf56acfd6e4b9c3ff41e2c41a31c9b211b2deb9df75d9a478f9L22-R22) [[2]](diffhunk://#diff-a54ff182c7e8acf56acfd6e4b9c3ff41e2c41a31c9b211b2deb9df75d9a478f9L98-R98) [[3]](diffhunk://#diff-a54ff182c7e8acf56acfd6e4b9c3ff41e2c41a31c9b211b2deb9df75d9a478f9L285-R285) [[4]](diffhunk://#diff-a54ff182c7e8acf56acfd6e4b9c3ff41e2c41a31c9b211b2deb9df75d9a478f9L311-R311) [[5]](diffhunk://#diff-a54ff182c7e8acf56acfd6e4b9c3ff41e2c41a31c9b211b2deb9df75d9a478f9L565-R565) ### Plugin and Widget Contributions * Added a new "I/O Utilities" widget to `napari.yaml` for easier access to file and export utilities from the napari interface. [[1]](diffhunk://#diff-37781c656dd096700e29a43b6a5fb914d4e9f1632516709c538774e9fb0e5149R21-R23) [[2]](diffhunk://#diff-37781c656dd096700e29a43b6a5fb914d4e9f1632516709c538774e9fb0e5149R72-R73) --- These changes collectively improve maintainability, usability, and extensibility of the codebase while introducing new features and ensuring consistency across settings and documentation.
1 parent 29379b4 commit 6b347af

27 files changed

+4728
-2430
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ repos:
77
- id: trailing-whitespace
88
exclude: ^\.napari-hub/.*
99
- id: check-yaml # checks for correct yaml syntax for github actions ex.
10+
exclude:
11+
(?x)(^src/ndevio/ndev_settings\.yaml$)
1012
- repo: https://github.com/astral-sh/ruff-pre-commit
1113
rev: v0.12.5
1214
hooks:
@@ -20,7 +22,7 @@ repos:
2022
hooks:
2123
- id: napari-plugin-checks
2224
- repo: https://github.com/ndev-kit/ndev-settings
23-
rev: v0.3.0
25+
rev: v0.4.0
2426
hooks:
2527
- id: reset-settings-values
2628
# https://mypy.readthedocs.io/en/stable/

AGENTS.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ uv venv
1919
.venv\Scripts\activate
2020
2121
# Install in editable mode with testing dependencies
22-
uv pip install -e ".[testing]"
22+
uv pip install -e . --group dev
2323
2424
# Run tests to verify setup
2525
pytest -v
@@ -95,7 +95,7 @@ This package is a **spiritual successor to napari-aicsimageio** but must be inde
9595
The reader selection follows a priority hierarchy:
9696

9797
1. **Explicit reader parameter** - If passed directly to function
98-
2. **User preference from settings** - `ndev_settings.ndevio_Reader.preferred_reader`
98+
2. **User preference from settings** - `ndev_settings.ndevio_reader.preferred_reader`
9999
3. **bioio feasibility check** - Verify preferred reader supports the file
100100
4. **bioio auto-detection** - Fallback to bioio's plugin determination
101101

@@ -282,7 +282,7 @@ ndevio/
282282
Settings defined in `ndev_settings.yaml`:
283283

284284
```yaml
285-
ndevio_Reader:
285+
ndevio_reader:
286286
preferred_reader:
287287
default: bioio-ome-tiff
288288
dynamic_choices:
@@ -308,7 +308,7 @@ ndevio_Reader:
308308
from ndev_settings import get_settings
309309

310310
settings = get_settings()
311-
preferred = settings.ndevio_Reader.preferred_reader
311+
preferred = settings.ndevio_reader.preferred_reader
312312
```
313313

314314
---
@@ -562,7 +562,7 @@ def get_reader(path):
562562
# CORRECT
563563
def get_preferred_reader(image, preferred_reader=None):
564564
settings = get_settings()
565-
preferred = preferred_reader or settings.ndevio_Reader.preferred_reader
565+
preferred = preferred_reader or settings.ndevio_reader.preferred_reader
566566

567567
# Use bioio's feasibility check
568568
fr = bioio.plugin_feasibility_report(image)

pixi.lock

Lines changed: 662 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,20 @@ requires-python = ">=3.11"
2828
# or any other Qt bindings directly (e.g. PyQt5, PySide2).
2929
# See best practices: https://napari.org/stable/plugins/building_a_plugin/best_practices.html
3030
dependencies = [
31-
"ndev-settings",
31+
"napari",
32+
"ndev-settings>=0.4.0",
33+
"nbatch>=0.0.4",
34+
"natsort",
35+
"magicgui",
36+
"magic-class",
3237
"xarray",
3338
"bioio-base",
3439
"bioio>=2", # migrates writers to plugins
3540
"bioio-ome-zarr>=3", # Pin to v3.x for zarr 3.x compatibility
3641
"bioio-ome-tiff>=1.2.0", # minimum for migrated writer
3742
"bioio-tifffile", # a backup tifffile reader with better performance than imageio
3843
"bioio-imageio",
39-
"zarr>=3.1.3", # Required: tifffile's ZarrTiffStore needs set_partial_values/supports_partial_writes
44+
"zarr>=3.1.3", # tifffile's ZarrTiffStore needs set_partial_values/supports_partial_writes
4045
"napari-plugin-manager>=0.1.7", # Renamed to PYPI from PIP for tool selection https://github.com/napari/napari-plugin-manager/pull/176
4146
]
4247

@@ -52,6 +57,7 @@ dev = [
5257
"pytest-qt", # https://pytest-qt.readthedocs.io/en/latest/
5358
"napari",
5459
"pyqt6", # Explicitly use PyQt6 (napari's future default, has ARM64 macOS support)
60+
"bioio-czi", # Include an additional priority reader for development/testing
5561
]
5662

5763
[project.entry-points."napari.manifest"]
@@ -82,6 +88,9 @@ xfail_strict = true
8288
log_cli_level = "INFO"
8389
testpaths = ["tests"]
8490

91+
[tool.coverage]
92+
report.fail_under = 80
93+
8594
[tool.black]
8695
line-length = 79
8796
target-version = ['py311', 'py312', 'py313']

src/ndevio/__init__.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
1+
from typing import TYPE_CHECKING
2+
13
try: # noqa: D104
24
from ._version import version as __version__
35
except ImportError:
46
__version__ = "unknown"
57

6-
from ._napari_reader import napari_get_reader
7-
from ._plugin_manager import ReaderPluginManager
8-
from .nimage import nImage
8+
from . import helpers
9+
10+
# Type stub for lazy import - lets type checkers know nImage exists
11+
if TYPE_CHECKING:
12+
from .nimage import nImage as nImage
13+
14+
15+
def __getattr__(name: str):
16+
"""Lazily import nImage to speed up package import."""
17+
if name == "nImage":
18+
from .nimage import nImage
19+
20+
return nImage
21+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
22+
923

10-
__all__ = ["__version__", "nImage", "napari_get_reader", "ReaderPluginManager"]
24+
__all__ = [
25+
"__version__",
26+
"helpers",
27+
"nImage",
28+
]

src/ndevio/_napari_reader.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ def napari_get_reader(
5151
open_first_scene_only = (
5252
open_first_scene_only
5353
if open_first_scene_only is not None
54-
else settings.ndevio_Reader.scene_handling == "View First Scene Only" # type: ignore
54+
else settings.ndevio_reader.scene_handling == "View First Scene Only" # type: ignore
5555
) or False
5656

5757
open_all_scenes = (
5858
open_all_scenes
5959
if open_all_scenes is not None
60-
else settings.ndevio_Reader.scene_handling == "View All Scenes" # type: ignore
60+
else settings.ndevio_reader.scene_handling == "View All Scenes" # type: ignore
6161
) or False
6262

6363
if isinstance(path, list):
@@ -78,7 +78,7 @@ def napari_get_reader(
7878
# determine_reader_plugin() already enhanced the error message
7979
logger.error("ndevio: Unsupported file format: %s", path)
8080
# Show plugin installer widget if enabled in settings
81-
if settings.ndevio_Reader.suggest_reader_plugins: # type: ignore
81+
if settings.ndevio_reader.suggest_reader_plugins: # type: ignore
8282
_open_plugin_installer(path, e)
8383

8484
# Return None per napari reader spec - don't raise exception

0 commit comments

Comments
 (0)