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

30 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-12-01 19:55 +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 typing import Any, Dict, Mapping, Optional, TYPE_CHECKING 

26 

27if TYPE_CHECKING: 27 ↛ 28line 27 didn't jump to line 28, because the condition on line 27 was never true

28 from .location import Location 

29 from .storageClass import StorageClass 

30 

31 

32class FileDescriptor: 

33 """Describes a particular file. 

34 

35 Parameters 

36 ---------- 

37 location : `Location` 

38 Storage location. 

39 storageClass : `StorageClass` 

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

41 readStorageClass : `StorageClass`, optional 

42 Storage class associated with reading the file. Defines the 

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

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

45 parameters : `dict`, optional 

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

47 """ 

48 

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

50 

51 def __init__(self, location: Location, 

52 storageClass: StorageClass, 

53 readStorageClass: Optional[StorageClass] = None, 

54 parameters: Optional[Mapping[str, Any]] = None): 

55 self.location = location 

56 self._readStorageClass = readStorageClass 

57 self.storageClass = storageClass 

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

59 

60 def __repr__(self) -> str: 

61 optionals: Dict[str, Any] = {} 

62 if self._readStorageClass is not None: 

63 optionals["readStorageClass"] = self._readStorageClass 

64 if self.parameters: 

65 optionals["parameters"] = self.parameters 

66 

67 # order is preserved in the dict 

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

69 

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

71 if options: 

72 r = r + ", " + options 

73 r = r + ")" 

74 return r 

75 

76 @property 

77 def readStorageClass(self) -> StorageClass: 

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

79 

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

81 """ 

82 if self._readStorageClass is None: 

83 return self.storageClass 

84 return self._readStorageClass