Skip to content

Commit

Permalink
Allow FileDataset to take a ButlerURI
Browse files Browse the repository at this point in the history
  • Loading branch information
timj committed Mar 17, 2021
1 parent 3c13ae5 commit ae4ddc2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
8 changes: 4 additions & 4 deletions python/lsst/daf/butler/core/fileDataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
Union,
)


from ._butlerUri import ButlerURI
from .datasets import DatasetRef
from .formatter import FormatterParameter

Expand All @@ -46,8 +46,8 @@ class FileDataset:
"""Registry information about the dataset. (`list` of `DatasetRef`).
"""

path: str
"""Path to the dataset (`str`).
path: Union[str, ButlerURI]
"""Path to the dataset (`str` or `ButlerURI`).
If the dataset was exported with ``transfer=None`` (i.e. in-place),
this is relative to the datastore root (only datastores that have a
Expand All @@ -72,4 +72,4 @@ def __lt__(self, other: Any) -> bool:
# Sort on path alone
if not isinstance(other, type(self)):
return NotImplemented
return self.path < other.path
return str(self.path) < str(other.path)
16 changes: 9 additions & 7 deletions python/lsst/daf/butler/datastores/fileDatastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,13 +687,13 @@ def _overrideTransferMode(self, *datasets: FileDataset, transfer: Optional[str]

return transfer

def _pathInStore(self, path: str) -> Optional[str]:
def _pathInStore(self, path: Union[str, ButlerURI]) -> Optional[str]:
"""Return path relative to datastore root
Parameters
----------
path : `str`
Path to dataset. Can be absolute. If relative assumed to
path : `str` or `ButlerURI`
Path to dataset. Can be absolute URI. If relative assumed to
be relative to the datastore. Returns path in datastore
or raises an exception if the path it outside.
Expand All @@ -707,12 +707,13 @@ def _pathInStore(self, path: str) -> Optional[str]:
pathUri = ButlerURI(path, forceAbsolute=False)
return pathUri.relative_to(self.root)

def _standardizeIngestPath(self, path: str, *, transfer: Optional[str] = None) -> str:
def _standardizeIngestPath(self, path: Union[str, ButlerURI], *,
transfer: Optional[str] = None) -> Union[str, ButlerURI]:
"""Standardize the path of a to-be-ingested file.
Parameters
----------
path : `str`
path : `str` or `ButlerURI`
Path of a file to be ingested.
transfer : `str`, optional
How (and whether) the dataset should be added to the datastore.
Expand All @@ -723,8 +724,9 @@ def _standardizeIngestPath(self, path: str, *, transfer: Optional[str] = None) -
Returns
-------
path : `str`
New path in what the datastore considers standard form.
path : `str` or `ButlerURI`
New path in what the datastore considers standard form. If an
absolute URI was given that will be returned unchanged.
Notes
-----
Expand Down
4 changes: 2 additions & 2 deletions python/lsst/daf/butler/transfers/_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

__all__ = ["YamlRepoExportBackend", "YamlRepoImportBackend"]

import os
from datetime import datetime
from typing import (
Any,
Expand Down Expand Up @@ -55,6 +54,7 @@
FileDataset,
Timespan,
)
from ..core._butlerUri import ButlerURI
from ..core.utils import iterable
from ..core.named import NamedValueSet
from ..registry import CollectionType, Registry
Expand Down Expand Up @@ -369,7 +369,7 @@ def load(self, datastore: Optional[Datastore], *,
for sliceForFileDataset, fileDataset in zip(slices, records):
fileDataset.refs = resolvedRefs[sliceForFileDataset]
if directory is not None:
fileDataset.path = os.path.join(directory, fileDataset.path)
fileDataset.path = ButlerURI(directory, forceDirectory=True).join(fileDataset.path)
fileDatasets.append(fileDataset)
# Ingest everything into the datastore at once.
if datastore is not None and fileDatasets:
Expand Down

0 comments on commit ae4ddc2

Please sign in to comment.