Skip to content

Commit

Permalink
Add butler.collections.register and register_run
Browse files Browse the repository at this point in the history
  • Loading branch information
timj committed Aug 15, 2024
1 parent 33619b0 commit 471f3fd
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
49 changes: 49 additions & 0 deletions python/lsst/daf/butler/_butler_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,52 @@ def get_info(self, name: str, include_doc: bool = False, include_parents: bool =
Information on the requested collection.
"""
raise NotImplementedError()

@abstractmethod
def register(self, name: str, type: CollectionType, doc: str | None = None) -> bool:
"""Add a new collection if one with the given name does not exist.
Parameters
----------
name : `str`
The name of the collection to create.
type : `CollectionType`
Enum value indicating the type of collection to create.
doc : `str`, optional
Documentation string for the collection.
Returns
-------
registered : `bool`
Boolean indicating whether the collection was already registered
or was created by this call.
Notes
-----
This method cannot be called within transactions, as it needs to be
able to perform its own transaction to be concurrent
"""
raise NotImplementedError()

def register_run(self, name: str, doc: str | None = None) -> bool:
"""Add a new run if one with the given name does not exist.
Parameters
----------
name : `str`
The name of the run to create.
doc : `str`, optional
Documentation string for the collection.
Returns
-------
registered : `bool`
Boolean indicating whether a new run was registered. `False`
if it already existed.
Notes
-----
This method cannot be called within transactions, as it needs to be
able to perform its own transaction to be concurrent.
"""
return self.register(name, CollectionType.RUN, doc)

Check warning on line 321 in python/lsst/daf/butler/_butler_collections.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/_butler_collections.py#L321

Added line #L321 was not covered by tests
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,6 @@ def get_info(self, name: str, include_doc: bool = False, include_parents: bool =
if include_parents:
parents = self._registry.getCollectionParentChains(name)
return CollectionInfo(name=name, type=record.type, doc=doc, parents=parents, children=children)

def register(self, name: str, type: CollectionType, doc: str | None = None) -> bool:
return self._registry.registerCollection(name, type, doc)

Check warning on line 113 in python/lsst/daf/butler/direct_butler/_direct_butler_collections.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/direct_butler/_direct_butler_collections.py#L113

Added line #L113 was not covered by tests
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,6 @@ def get_info(self, name: str, include_doc: bool = False, include_parents: bool =
children = info.children or ()
parents = info.parents or set()
return CollectionInfo(name=name, type=info.type, doc=doc, parents=parents, children=children)

Check warning on line 97 in python/lsst/daf/butler/remote_butler/_remote_butler_collections.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/remote_butler/_remote_butler_collections.py#L94-L97

Added lines #L94 - L97 were not covered by tests

def register(self, name: str, type: CollectionType, doc: str | None = None) -> bool:
raise NotImplementedError("Not yet available.")

0 comments on commit 471f3fd

Please sign in to comment.