Coverage for python/lsst/daf/butler/core/fileDescriptor.py: 30%

28 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-08-12 09:20 +0000

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/>. 

21from __future__ import annotations 

22 

23__all__ = ("FileDescriptor",) 

24 

25from collections.abc import Mapping 

26from typing import TYPE_CHECKING, Any 

27 

28if TYPE_CHECKING: 

29 from .location import Location 

30 from .storageClass import StorageClass 

31 

32 

33class FileDescriptor: 

34 """Describes a particular file. 

35 

36 Parameters 

37 ---------- 

38 location : `Location` 

39 Storage location. 

40 storageClass : `StorageClass` 

41 `StorageClass` associated with this file when it was stored. 

42 readStorageClass : `StorageClass`, optional 

43 Storage class associated with reading the file. Defines the 

44 Python type that the in memory Dataset will have. Will default 

45 to the ``storageClass`` if not specified. 

46 parameters : `dict`, optional 

47 Additional parameters that can be used for reading and writing. 

48 """ 

49 

50 __slots__ = ("location", "storageClass", "_readStorageClass", "parameters") 

51 

52 def __init__( 

53 self, 

54 location: Location, 

55 storageClass: StorageClass, 

56 readStorageClass: StorageClass | None = None, 

57 parameters: Mapping[str, Any] | None = None, 

58 ): 

59 self.location = location 

60 self._readStorageClass = readStorageClass 

61 self.storageClass = storageClass 

62 self.parameters = dict(parameters) if parameters is not None else None 

63 

64 def __repr__(self) -> str: 

65 optionals: dict[str, Any] = {} 

66 if self._readStorageClass is not None: 

67 optionals["readStorageClass"] = self._readStorageClass 

68 if self.parameters: 

69 optionals["parameters"] = self.parameters 

70 

71 # order is preserved in the dict 

72 options = ", ".join(f"{k}={v!r}" for k, v in optionals.items()) 

73 

74 r = f"{self.__class__.__name__}({self.location!r}, {self.storageClass!r}" 

75 if options: 

76 r = r + ", " + options 

77 r = r + ")" 

78 return r 

79 

80 @property 

81 def readStorageClass(self) -> StorageClass: 

82 """Storage class to use when reading. (`StorageClass`). 

83 

84 Will default to ``storageClass`` if none specified. 

85 """ 

86 if self._readStorageClass is None: 

87 return self.storageClass 

88 return self._readStorageClass