Skip to content

Commit

Permalink
Add Butler._caching_context method.
Browse files Browse the repository at this point in the history
Registry shiim now redirects to this method instead of Registry
method. RemoteButler raises NotImplementedError but may do something
non-trivial later when we know how caching is going to work with
client/server.
  • Loading branch information
andy-slac committed Nov 14, 2023
1 parent eaa968d commit 922359c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
5 changes: 5 additions & 0 deletions python/lsst/daf/butler/_butler.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,11 @@ def get_known_repos(cls) -> set[str]:
"""
return ButlerRepoIndex.get_known_repos()

@abstractmethod
def _caching_context(self) -> AbstractContextManager[None]:
"""Context manager that enables caching."""
raise NotImplementedError()

@abstractmethod
def transaction(self) -> AbstractContextManager[None]:
"""Context manager supporting `Butler` transactions.
Expand Down
6 changes: 2 additions & 4 deletions python/lsst/daf/butler/_registry_shim.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,9 @@ def refresh(self) -> None:
# Docstring inherited from a base class.
self._registry.refresh()

@contextlib.contextmanager
def caching_context(self) -> Iterator[None]:
def caching_context(self) -> contextlib.AbstractContextManager[None]:
# Docstring inherited from a base class.
with self._registry.caching_context():
yield
return self._butler._caching_context()

Check warning on line 107 in python/lsst/daf/butler/_registry_shim.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/_registry_shim.py#L107

Added line #L107 was not covered by tests

@contextlib.contextmanager
def transaction(self, *, savepoint: bool = False) -> Iterator[None]:
Expand Down
4 changes: 4 additions & 0 deletions python/lsst/daf/butler/direct_butler.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ def isWriteable(self) -> bool:
# Docstring inherited.
return self._registry.isWriteable()

def _caching_context(self) -> contextlib.AbstractContextManager[None]:
"""Context manager that enables caching."""
return self._registry.caching_context()

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

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/direct_butler.py#L304

Added line #L304 was not covered by tests

@contextlib.contextmanager
def transaction(self) -> Iterator[None]:
"""Context manager supporting `Butler` transactions.
Expand Down
3 changes: 1 addition & 2 deletions python/lsst/daf/butler/registry/_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,8 @@ def refresh(self) -> None:
"""
raise NotImplementedError()

@contextlib.contextmanager
@abstractmethod
def caching_context(self) -> Iterator[None]:
def caching_context(self) -> contextlib.AbstractContextManager[None]:
"""Context manager that enables caching."""
raise NotImplementedError()

Expand Down
6 changes: 6 additions & 0 deletions python/lsst/daf/butler/remote_butler/_remote_butler.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ def _simplify_dataId(
# Assume we can treat it as a dict.
return SerializedDataCoordinate(dataId=data_id)

def _caching_context(self) -> AbstractContextManager[None]:
# Docstring inherited.
# Not implemented for now, will have to think whether this needs to
# do something on client side and/or remote side.
raise NotImplementedError()

def transaction(self) -> AbstractContextManager[None]:
"""Will always raise NotImplementedError.
Transactions are not supported by RemoteButler.
Expand Down

0 comments on commit 922359c

Please sign in to comment.