Skip to content

Commit

Permalink
Allow remote butler factory to set datastore cache status
Browse files Browse the repository at this point in the history
  • Loading branch information
timj committed Aug 20, 2024
1 parent 48d9216 commit cd7a019
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
6 changes: 5 additions & 1 deletion python/lsst/daf/butler/_butler.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,12 @@ def from_config(
case ButlerType.REMOTE:
from .remote_butler import RemoteButlerFactory

# Assume this is being created by a client who would like
# default caching of remote datasets.
factory = RemoteButlerFactory.create_factory_from_config(butler_config)
return factory.create_butler_with_credentials_from_environment(butler_options=options)
return factory.create_butler_with_credentials_from_environment(
butler_options=options, use_disabled_datastore_cache=False
)
case _:
raise TypeError(f"Unknown Butler type '{butler_type}'")

Expand Down
16 changes: 13 additions & 3 deletions python/lsst/daf/butler/remote_butler/_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ def create_factory_for_url(server_url: str) -> RemoteButlerFactory:
return RemoteButlerFactory(server_url)

def create_butler_for_access_token(
self, access_token: str, *, butler_options: ButlerInstanceOptions | None = None
self,
access_token: str,
*,
butler_options: ButlerInstanceOptions | None = None,
use_disabled_datastore_cache: bool = True,
) -> RemoteButler:
if butler_options is None:
butler_options = ButlerInstanceOptions()
Expand All @@ -97,15 +101,21 @@ def create_butler_for_access_token(
),
options=butler_options,
cache=self._cache,
use_disabled_datastore_cache=use_disabled_datastore_cache,
)

def create_butler_with_credentials_from_environment(
self, *, butler_options: ButlerInstanceOptions | None = None
self,
*,
butler_options: ButlerInstanceOptions | None = None,
use_disabled_datastore_cache: bool = True,
) -> RemoteButler:
token = get_authentication_token_from_environment(self.server_url)
if token is None:
raise RuntimeError(
"Attempting to connect to Butler server,"
" but no access credentials were found in the environment."
)
return self.create_butler_for_access_token(token, butler_options=butler_options)
return self.create_butler_for_access_token(
token, butler_options=butler_options, use_disabled_datastore_cache=use_disabled_datastore_cache
)

0 comments on commit cd7a019

Please sign in to comment.