Skip to content

Commit 499c0c8

Browse files
committed
Add dvue entry point for SCHISM readers and refactor registration function
1 parent ebc0f91 commit 499c0c8

3 files changed

Lines changed: 48 additions & 18 deletions

File tree

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ suxarray = [
6262
[project.scripts]
6363
schismviz = "schismviz.cli:main"
6464

65+
[project.entry-points."dvue.plugins"]
66+
schismviz = "schismviz.readers:register_readers"
67+
6568
[project.urls]
6669
Homepage = "https://github.com/cadwrdeltamodeling/schismviz"
6770
Documentation = "https://github.com/cadwrdeltamodeling/schismviz#readme"

schismviz/readers.py

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
dvue ui --plugin schismviz.readers /path/to/study/param.nml
88
dvue ui --plugin schismviz.readers /path/to/schism_studies.yaml
99
10-
The registration call at the bottom of this module fires at import time,
11-
so all three entry points work:
10+
The :func:`register_readers` function is used by setuptools entry points
11+
(``dvue.plugins`` group). For backward compatibility, registration also
12+
fires at import time, so all three entry points work:
1213
1314
1. ``dvue ui --plugin schismviz.readers`` (generic dvue combine UI)
1415
2. ``schismviz combine`` (SCHISM-specific combine UI via this package's CLI)
@@ -534,21 +535,33 @@ def is_irregular(self, r) -> bool:
534535

535536

536537
# ---------------------------------------------------------------------------
537-
# Registration — runs at import time
538+
# Registration
538539
# ---------------------------------------------------------------------------
539540

540-
# Compound NML extensions (.nml.clinic, .nml.barotropic, .nml.tropic) are
541-
# identified by their *last* suffix via os.path.splitext in the registry;
542-
# scan() inspects the full suffix chain to confirm the .nml prefix.
543-
ReaderRegistry.register(
544-
"schism_output",
545-
SchismOutputReader,
546-
extensions=[
547-
".nml",
548-
".clinic",
549-
".barotropic",
550-
".tropic",
551-
".yaml",
552-
".yml",
553-
],
554-
)
541+
542+
def register_readers() -> None:
543+
"""Register SCHISM readers with dvue's :class:`ReaderRegistry`.
544+
545+
This is the callable referenced by the ``dvue.plugins`` entry point:
546+
547+
``schismviz = \"schismviz.readers:register_readers\"``.
548+
"""
549+
550+
# Compound NML extensions (.nml.clinic, .nml.barotropic, .nml.tropic) are
551+
# identified by their *last* suffix via os.path.splitext in the registry;
552+
# scan() inspects the full suffix chain to confirm the .nml prefix.
553+
ReaderRegistry.register(
554+
"schism_output",
555+
SchismOutputReader,
556+
extensions=[
557+
".nml",
558+
".clinic",
559+
".barotropic",
560+
".tropic",
561+
".yaml",
562+
".yml",
563+
],
564+
)
565+
566+
# Backward compatibility: preserve import-time registration behavior.
567+
register_readers()

tests/test_readers.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,20 @@ def test_registration_on_import():
3535
assert ReaderRegistry.can_handle("param.nml.tropic"), ".nml.tropic not registered"
3636

3737

38+
def test_register_readers_function_registers_plugin_mappings():
39+
"""register_readers() maps schism_output and supported extensions."""
40+
from schismviz.readers import SchismOutputReader, register_readers
41+
42+
register_readers()
43+
44+
readers = ReaderRegistry.get_registered_readers()
45+
extensions = ReaderRegistry.get_registered_extensions()
46+
47+
assert readers.get("schism_output") is SchismOutputReader
48+
for ext in [".nml", ".clinic", ".barotropic", ".tropic", ".yaml", ".yml"]:
49+
assert extensions.get(ext) is SchismOutputReader
50+
51+
3852
def test_ref_type():
3953
"""SchismDataReference advertises ref_type='schism_output'."""
4054
from schismviz.readers import SchismDataReference

0 commit comments

Comments
 (0)