Coverage for python/lsst/daf/butler/core/fileDataset.py: 62%
26 statements
« prev ^ index » next coverage.py v6.4.1, created at 2022-06-15 02:06 -0700
« prev ^ index » next coverage.py v6.4.1, created at 2022-06-15 02:06 -0700
1# This file is part of daf_butler.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (http://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <http://www.gnu.org/licenses/>.
22from __future__ import annotations
24__all__ = ["FileDataset"]
26from dataclasses import dataclass
27from typing import Any, List, Optional, Union
29from lsst.resources import ResourcePath, ResourcePathExpression
31from .datasets import DatasetRef
32from .formatter import FormatterParameter
35@dataclass
36class FileDataset:
37 """A struct that represents a dataset exported to a file."""
39 __slots__ = ("refs", "path", "formatter")
41 refs: List[DatasetRef]
42 """Registry information about the dataset. (`list` of `DatasetRef`).
43 """
45 path: Union[str, ResourcePath]
46 """Path to the dataset (`lsst.resources.ResourcePath` or `str`).
48 If the dataset was exported with ``transfer=None`` (i.e. in-place),
49 this is relative to the datastore root (only datastores that have a
50 well-defined root in the local filesystem can be expected to support
51 in-place exports). Otherwise this is relative to the directory passed
52 to `Datastore.export`.
53 """
55 formatter: Optional[FormatterParameter]
56 """A `Formatter` class or fully-qualified name.
57 """
59 def __init__(
60 self,
61 path: ResourcePathExpression,
62 refs: Union[DatasetRef, List[DatasetRef]],
63 *,
64 formatter: Optional[FormatterParameter] = None,
65 ):
66 # Do not want to store all possible options supported by ResourcePath
67 # so force a conversion for the non-str parameters.
68 self.path = path if isinstance(path, str) else ResourcePath(path, forceAbsolute=False)
69 if isinstance(refs, DatasetRef):
70 refs = [refs]
71 self.refs = refs
72 self.formatter = formatter
74 def __lt__(self, other: Any) -> bool:
75 # Sort on path alone
76 if not isinstance(other, type(self)):
77 return NotImplemented
78 return str(self.path) < str(other.path)