From 7eab7d5238959b4a6a67713b7fe48fcdc204c43c Mon Sep 17 00:00:00 2001 From: "David H. Irving" Date: Wed, 25 Oct 2023 10:47:24 -0700 Subject: [PATCH] Implement collections and run in RemoteButler --- .../lsst/daf/butler/remote_butler/_remote_butler.py | 13 ++++++++++--- tests/test_remote_butler.py | 6 +++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/python/lsst/daf/butler/remote_butler/_remote_butler.py b/python/lsst/daf/butler/remote_butler/_remote_butler.py index 777db8d3b9..5f21417a21 100644 --- a/python/lsst/daf/butler/remote_butler/_remote_butler.py +++ b/python/lsst/daf/butler/remote_butler/_remote_butler.py @@ -46,7 +46,7 @@ from .._storage_class import StorageClass from ..datastore import DatasetRefURIs from ..dimensions import DataId, DimensionConfig, DimensionUniverse -from ..registry import Registry +from ..registry import Registry, RegistryDefaults from ..transfers import RepoExportContext from ._config import RemoteButlerConfigModel @@ -57,7 +57,11 @@ def __init__( # These parameters are inherited from the Butler() constructor config: Config | ResourcePathExpression | None = None, *, + collections: Any = None, + run: str | None = None, searchPaths: Sequence[ResourcePathExpression] | None = None, + writeable: bool | None = None, + inferDefaults: bool = True, # Parameters unique to RemoteButler http_client: httpx.Client | None = None, **kwargs: Any, @@ -65,6 +69,9 @@ def __init__( butler_config = ButlerConfig(config, searchPaths, without_datastore=True) self._config = RemoteButlerConfigModel.model_validate(butler_config) self._dimensions: DimensionUniverse | None = None + # TODO: RegistryDefaults should have finish() called on it, but this + # requires getCollectionSummary() which is not yet implemented + self._registry_defaults = RegistryDefaults(collections, run, inferDefaults, **kwargs) if http_client is not None: # We have injected a client explicitly in to the class. @@ -266,12 +273,12 @@ def validateConfiguration( @property def collections(self) -> Sequence[str]: # Docstring inherited. - raise NotImplementedError() + return self._registry_defaults.collections @property def run(self) -> str | None: # Docstring inherited. - raise NotImplementedError() + return self._registry_defaults.run @property def registry(self) -> Registry: diff --git a/tests/test_remote_butler.py b/tests/test_remote_butler.py index 1caf41bae1..096a302d47 100644 --- a/tests/test_remote_butler.py +++ b/tests/test_remote_butler.py @@ -47,9 +47,13 @@ def test_instantiate_via_butler(self): { "cls": "lsst.daf.butler.remote_butler.RemoteButler", "remote_butler": {"url": "https://validurl.example"}, - } + }, + collections=["collection1", "collection2"], + run="collection2", ) assert isinstance(butler, RemoteButler) + self.assertEqual(butler.collections, ("collection1", "collection2")) + self.assertEqual(butler.run, "collection2") def test_bad_config(self): with self.assertRaises(ValidationError):