Skip to content

Commit

Permalink
Support repo aliases in Butler constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
timj committed Mar 2, 2022
1 parent b093713 commit 301c21a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
11 changes: 11 additions & 0 deletions python/lsst/daf/butler/_butler.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,17 @@ def __init__(
self._config: ButlerConfig = butler._config
self._allow_put_of_predefined_dataset = butler._allow_put_of_predefined_dataset
else:
# Can only look for strings in the known repos list.
if isinstance(config, str) and config in self.get_known_repos():
config = str(self.get_repo_uri(config))
try:
self._config = ButlerConfig(config, searchPaths=searchPaths)
except FileNotFoundError as e:
if known := self.get_known_repos():
aliases = f"(known aliases {', '.join(known)})"
else:
aliases = "(no known aliases)"
raise FileNotFoundError(f"{e} {aliases}") from e
self._config = ButlerConfig(config, searchPaths=searchPaths)
try:
if "root" in self._config:
Expand Down
5 changes: 5 additions & 0 deletions tests/test_butler.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,11 @@ def testConstructor(self):
uri = Butler.get_repo_uri("label")
butler = Butler(uri, writeable=False)
self.assertIsInstance(butler, Butler)
butler = Butler("label", writeable=False)
self.assertIsInstance(butler, Butler)
with self.assertRaises(FileNotFoundError) as cm:
Butler("not_there", writeable=False)
self.assertIn("label", str(cm.exception))
with self.assertRaises(KeyError) as cm:
Butler.get_repo_uri("missing")
self.assertIn("not known to", str(cm.exception))
Expand Down

0 comments on commit 301c21a

Please sign in to comment.