Skip to content

Commit

Permalink
Forward RemoteButlerRegistry to ButlerCollections
Browse files Browse the repository at this point in the history
Now that there is an independent implementation of ButlerCollections for RemoteButler, forward the equivalent Registry methods to it to reduce duplication.
  • Loading branch information
dhirving committed Sep 9, 2024
1 parent f50f5cb commit 91b14a5
Showing 1 changed file with 11 additions and 26 deletions.
37 changes: 11 additions & 26 deletions python/lsst/daf/butler/remote_butler/_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@
from .server_models import (
ExpandDataIdRequestModel,
ExpandDataIdResponseModel,
GetCollectionInfoResponseModel,
GetCollectionSummaryResponseModel,
QueryCollectionsRequestModel,
QueryCollectionsResponseModel,
QueryDatasetTypesRequestModel,
QueryDatasetTypesResponseModel,
)
Expand Down Expand Up @@ -145,7 +142,7 @@ def registerCollection(
raise NotImplementedError()

def getCollectionType(self, name: str) -> CollectionType:
return self._get_collection_info(name).type
return self._butler.collections.get_info(name).type

def registerRun(self, name: str, doc: str | None = None) -> bool:
raise NotImplementedError()
Expand All @@ -154,7 +151,7 @@ def removeCollection(self, name: str) -> None:
raise NotImplementedError()

def getCollectionChain(self, parent: str) -> Sequence[str]:
info = self._get_collection_info(parent)
info = self._butler.collections.get_info(parent)
if info.type is not CollectionType.CHAINED:
raise CollectionTypeError(f"Collection '{parent}' has type {info.type.name}, not CHAINED.")
return info.children
Expand All @@ -163,26 +160,19 @@ def setCollectionChain(self, parent: str, children: Any, *, flatten: bool = Fals
raise NotImplementedError()

def getCollectionParentChains(self, collection: str) -> set[str]:
info = self._get_collection_info(collection, include_parents=True)
info = self._butler.collections.get_info(collection, include_parents=True)
assert info.parents is not None, "Requested list of parents from server, but it did not send them."
return info.parents
return set(info.parents)

def getCollectionDocumentation(self, collection: str) -> str | None:
info = self._get_collection_info(collection, include_doc=True)
return info.doc
doc = self._butler.collections.get_info(collection).doc
if not doc:
return None
return doc

def setCollectionDocumentation(self, collection: str, doc: str | None) -> None:
raise NotImplementedError()

def _get_collection_info(
self, collection_name: str, include_doc: bool = False, include_parents: bool = False
) -> GetCollectionInfoResponseModel:
response = self._connection.get(
"collection_info",
{"name": collection_name, "include_doc": include_doc, "include_parents": include_parents},
)
return parse_model(response, GetCollectionInfoResponseModel)

def getCollectionSummary(self, collection: str) -> CollectionSummary:
response = self._connection.get("collection_summary", {"name": collection})
parsed = parse_model(response, GetCollectionSummaryResponseModel)
Expand Down Expand Up @@ -356,18 +346,13 @@ def queryCollections(
flattenChains: bool = False,
includeChains: bool | None = None,
) -> Sequence[str]:
if includeChains is None:
includeChains = not flattenChains
query = QueryCollectionsRequestModel(
search=convert_collection_arg_to_glob_string_list(expression),
collection_types=list(ensure_iterable(collectionTypes)),
return self._butler.collections.query(
expression,
collection_types=set(ensure_iterable(collectionTypes)),
flatten_chains=flattenChains,
include_chains=includeChains,
)

response = self._connection.post("query_collections", query)
return parse_model(response, QueryCollectionsResponseModel).collections

def queryDatasets(
self,
datasetType: Any,
Expand Down

0 comments on commit 91b14a5

Please sign in to comment.