Coverage for python/lsst/daf/butler/core/fileDataset.py: 62%

26 statements  

« prev     ^ index     » next       coverage.py v6.4.2, created at 2022-08-04 02:20 -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/>. 

21 

22from __future__ import annotations 

23 

24__all__ = ["FileDataset"] 

25 

26from dataclasses import dataclass 

27from typing import Any, List, Optional, Union 

28 

29from lsst.resources import ResourcePath, ResourcePathExpression 

30 

31from .datasets import DatasetRef 

32from .formatter import FormatterParameter 

33 

34 

35@dataclass 

36class FileDataset: 

37 """A struct that represents a dataset exported to a file.""" 

38 

39 __slots__ = ("refs", "path", "formatter") 

40 

41 refs: List[DatasetRef] 

42 """Registry information about the dataset. (`list` of `DatasetRef`). 

43 """ 

44 

45 path: Union[str, ResourcePath] 

46 """Path to the dataset (`lsst.resources.ResourcePath` or `str`). 

47 

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 """ 

54 

55 formatter: Optional[FormatterParameter] 

56 """A `Formatter` class or fully-qualified name. 

57 """ 

58 

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 

73 

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)