Coverage for python/lsst/daf/butler/core/fileDescriptor.py: 30%
30 statements
« prev ^ index » next coverage.py v6.4.4, created at 2022-09-15 09:41 +0000
« prev ^ index » next coverage.py v6.4.4, created at 2022-09-15 09:41 +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
23__all__ = ("FileDescriptor",)
25from typing import TYPE_CHECKING, Any, Dict, Mapping, Optional
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
32class FileDescriptor:
33 """Describes a particular file.
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 """
49 __slots__ = ("location", "storageClass", "_readStorageClass", "parameters")
51 def __init__(
52 self,
53 location: Location,
54 storageClass: StorageClass,
55 readStorageClass: Optional[StorageClass] = None,
56 parameters: Optional[Mapping[str, Any]] = None,
57 ):
58 self.location = location
59 self._readStorageClass = readStorageClass
60 self.storageClass = storageClass
61 self.parameters = dict(parameters) if parameters is not None else None
63 def __repr__(self) -> str:
64 optionals: Dict[str, Any] = {}
65 if self._readStorageClass is not None:
66 optionals["readStorageClass"] = self._readStorageClass
67 if self.parameters:
68 optionals["parameters"] = self.parameters
70 # order is preserved in the dict
71 options = ", ".join(f"{k}={v!r}" for k, v in optionals.items())
73 r = f"{self.__class__.__name__}({self.location!r}, {self.storageClass!r}"
74 if options:
75 r = r + ", " + options
76 r = r + ")"
77 return r
79 @property
80 def readStorageClass(self) -> StorageClass:
81 """Storage class to use when reading. (`StorageClass`).
83 Will default to ``storageClass`` if none specified.
84 """
85 if self._readStorageClass is None:
86 return self.storageClass
87 return self._readStorageClass