Skip to content

Commit

Permalink
Fix logic for appending butler.yaml to remote butler config URIs
Browse files Browse the repository at this point in the history
  • Loading branch information
timj committed Apr 30, 2021
1 parent 0f59b06 commit 39f3195
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions python/lsst/daf/butler/_butlerConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
__all__ = ("ButlerConfig",)

import copy
import os.path
from typing import (
Optional,
Sequence,
Expand Down Expand Up @@ -87,20 +86,27 @@ def __init__(self, other: Optional[Union[str, ButlerURI, Config]] = None,
if isinstance(other, str):
# This will only allow supported schemes
uri = ButlerURI(other)
if uri.isLocal:
# Check explicitly that we have a directory
if os.path.isdir(uri.ospath):
other = uri.join("butler.yaml")
else:
# For generic URI assume that we have a directory
# if the basename does not have a file extension
# This heuristic is needed since we can not rely on
# external users to include the trailing / and we
# can't always check that the remote resource is a directory.
if not uri.dirLike and not uri.getExtension():
# Force to a directory and add the default config name
uri = ButlerURI(other, forceDirectory=True).join("butler.yaml")
other = uri

# We allow the butler configuration file to be left off the
# URI supplied by the user. If a directory-like URI is given
# we add the default configuration name.
should_append = False
if uri.isdir():
should_append = True
elif not uri.isLocal and not uri.getExtension():
# For remote URI people can easily forget to add the trailing
# slash. Attempt to fix this up by assuming that if
# the URI is remote and has no file extension then it is
# probably meant to be a directory.
uri = ButlerURI(other, forceDirectory=True)
should_append = True

if should_append:
# Could also be butler.json (for example in the butler
# server) but checking for existence will slow things
# down given that this might involve two checks and then
# the config read below would still do the read.
other = uri.join("butler.yaml")

# Create an empty config for us to populate
super().__init__()
Expand Down

0 comments on commit 39f3195

Please sign in to comment.