Skip to content

Commit ac63839

Browse files
committed
feat: Enhance plugin integration and time range handling in RegistryUIManager
1 parent f26a965 commit ac63839

2 files changed

Lines changed: 55 additions & 7 deletions

File tree

dvue/cli.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,10 @@ def ui_command(files, plugins, port, desktop):
7777
"""
7878
import importlib
7979

80+
plugin_modules = []
8081
for module_name in plugins:
8182
try:
82-
importlib.import_module(module_name)
83+
plugin_modules.append(importlib.import_module(module_name))
8384
except ImportError as exc:
8485
raise click.ClickException(
8586
f"Could not import plugin module {module_name!r}: {exc}"
@@ -88,13 +89,24 @@ def ui_command(files, plugins, port, desktop):
8889
from dvue.registry_ui import RegistryUIManager
8990
from dvue.session_persistence import serve_session_app, serve_desktop_app
9091

92+
manager_cls = RegistryUIManager
93+
effective_crs = None
94+
for mod in plugin_modules:
95+
# Optional plugin hook: module-level manager override.
96+
# Last plugin wins when multiple plugins provide this symbol.
97+
if hasattr(mod, "DVueUIManager"):
98+
manager_cls = getattr(mod, "DVueUIManager")
99+
# Optional plugin hook: module-level map CRS override.
100+
if hasattr(mod, "DVueUI_CRS"):
101+
effective_crs = getattr(mod, "DVueUI_CRS")
102+
91103
file_list = list(files)
92104

93105
def build_manager():
94-
return RegistryUIManager(files=file_list)
106+
return manager_cls(files=file_list)
95107

96108
_serve = serve_desktop_app if desktop else serve_session_app
97-
_serve(build_manager, title="dvue UI", port=port)
109+
_serve(build_manager, title="dvue UI", port=port, crs=effective_crs)
98110

99111

100112
if __name__ == "__main__":

dvue/registry_ui.py

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,16 @@ def normalize_ref(self, ref: "DataReference") -> None:
181181
def on_file_added(self, path: str, refs: List["DataReference"]) -> None:
182182
"""Hook called after a file's refs have been successfully added.
183183
184-
Override to perform file-level side effects such as expanding
185-
``self.time_range``, loading geometry from a companion file, or
186-
registering the source in an external index.
184+
Default implementation: expands ``self.time_range`` to cover the
185+
data extent of any newly added refs. Readers declare their data's
186+
time extent by storing ``time_extent_start`` and ``time_extent_end``
187+
attributes (ISO-8601 strings or any ``pd.Timestamp``-coercible value)
188+
on each :class:`~dvue.catalog.DataReference`.
187189
188-
The default is a no-op.
190+
Subclasses that need additional side-effects (loading geometry,
191+
registering external indices, etc.) should call
192+
``super().on_file_added(path, refs)`` so that time_range expansion
193+
still happens.
189194
190195
Parameters
191196
----------
@@ -195,6 +200,37 @@ def on_file_added(self, path: str, refs: List["DataReference"]) -> None:
195200
All refs returned by ``ReaderRegistry.scan(path)`` for this file
196201
(including any that were skipped due to pk collisions).
197202
"""
203+
starts = []
204+
ends = []
205+
seen: set = set()
206+
for ref in refs:
207+
s = ref._attributes.get("time_extent_start")
208+
e = ref._attributes.get("time_extent_end")
209+
key = (s, e)
210+
if key in seen or not s:
211+
continue
212+
seen.add(key)
213+
try:
214+
starts.append(pd.Timestamp(s))
215+
except Exception:
216+
pass
217+
if e:
218+
try:
219+
ends.append(pd.Timestamp(e))
220+
except Exception:
221+
pass
222+
if not starts:
223+
return
224+
new_start = min(starts)
225+
new_end = max(ends) if ends else new_start + pd.Timedelta(days=366)
226+
current = self.time_range
227+
if current is None:
228+
self.time_range = (new_start, new_end)
229+
else:
230+
self.time_range = (
231+
min(current[0], new_start),
232+
max(current[1], new_end),
233+
)
198234

199235
# ------------------------------------------------------------------
200236
# Geo / map integration

0 commit comments

Comments
 (0)