Coverage for python/lsst/daf/butler/_registry_shim.py: 60%

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

21 

22from __future__ import annotations 

23 

24__all__ = ("Registry",) 

25 

26import contextlib 

27from collections.abc import Iterable, Iterator, Mapping, Sequence 

28from typing import TYPE_CHECKING, Any 

29 

30from .core import ( 

31 DataCoordinate, 

32 DataId, 

33 DatasetAssociation, 

34 DatasetId, 

35 DatasetIdGenEnum, 

36 DatasetRef, 

37 DatasetType, 

38 Dimension, 

39 DimensionElement, 

40 DimensionGraph, 

41 DimensionRecord, 

42 DimensionUniverse, 

43 NameLookupMapping, 

44 Timespan, 

45) 

46from .registry import Registry 

47from .registry._collection_summary import CollectionSummary 

48from .registry._collectionType import CollectionType 

49from .registry._defaults import RegistryDefaults 

50from .registry.queries import DataCoordinateQueryResults, DatasetQueryResults, DimensionRecordQueryResults 

51 

52if TYPE_CHECKING: 

53 from ._butler import Butler 

54 from .registry._registry import CollectionArgType 

55 from .registry.interfaces import ObsCoreTableManager 

56 

57 

58class RegistryShim(Registry): 

59 """Implementation of `Registry` interface exposed to clients by `Butler`. 

60 

61 Parameters 

62 ---------- 

63 butler : `Butler` 

64 Data butler instance. 

65 

66 Notes 

67 ----- 

68 This shim implementation of `Registry` forwards all methods to an actual 

69 Registry instance which is internal to Butler or to Butler methods. Its 

70 purpose is to provide a stable interface to many client-visible operations 

71 while we perform re-structuring of Registry and Butler implementations. 

72 """ 

73 

74 def __init__(self, butler: Butler): 

75 self._butler = butler 

76 self._registry = butler._registry 

77 

78 def isWriteable(self) -> bool: 

79 # Docstring inherited from a base class. 

80 return self._registry.isWriteable() 

81 

82 @property 

83 def dimensions(self) -> DimensionUniverse: 

84 # Docstring inherited from a base class. 

85 return self._registry.dimensions 

86 

87 @property 

88 def defaults(self) -> RegistryDefaults: 

89 # Docstring inherited from a base class. 

90 return self._registry.defaults 

91 

92 @defaults.setter 

93 def defaults(self, value: RegistryDefaults) -> None: 

94 # Docstring inherited from a base class. 

95 self._registry.defaults = value 

96 

97 def refresh(self) -> None: 

98 # Docstring inherited from a base class. 

99 self._registry.refresh() 

100 

101 @contextlib.contextmanager 

102 def transaction(self, *, savepoint: bool = False) -> Iterator[None]: 

103 # Docstring inherited from a base class. 

104 with self._registry.transaction(savepoint=savepoint): 

105 yield 

106 

107 def resetConnectionPool(self) -> None: 

108 # Docstring inherited from a base class. 

109 self._registry.resetConnectionPool() 

110 

111 def registerCollection( 

112 self, name: str, type: CollectionType = CollectionType.TAGGED, doc: str | None = None 

113 ) -> bool: 

114 # Docstring inherited from a base class. 

115 return self._registry.registerCollection(name, type, doc) 

116 

117 def getCollectionType(self, name: str) -> CollectionType: 

118 # Docstring inherited from a base class. 

119 return self._registry.getCollectionType(name) 

120 

121 def registerRun(self, name: str, doc: str | None = None) -> bool: 

122 # Docstring inherited from a base class. 

123 return self._registry.registerRun(name, doc) 

124 

125 def removeCollection(self, name: str) -> None: 

126 # Docstring inherited from a base class. 

127 self._registry.removeCollection(name) 

128 

129 def getCollectionChain(self, parent: str) -> Sequence[str]: 

130 # Docstring inherited from a base class. 

131 return self._registry.getCollectionChain(parent) 

132 

133 def setCollectionChain(self, parent: str, children: Any, *, flatten: bool = False) -> None: 

134 # Docstring inherited from a base class. 

135 self._registry.setCollectionChain(parent, children, flatten=flatten) 

136 

137 def getCollectionParentChains(self, collection: str) -> set[str]: 

138 # Docstring inherited from a base class. 

139 return self._registry.getCollectionParentChains(collection) 

140 

141 def getCollectionDocumentation(self, collection: str) -> str | None: 

142 # Docstring inherited from a base class. 

143 return self._registry.getCollectionDocumentation(collection) 

144 

145 def setCollectionDocumentation(self, collection: str, doc: str | None) -> None: 

146 # Docstring inherited from a base class. 

147 self._registry.setCollectionDocumentation(collection, doc) 

148 

149 def getCollectionSummary(self, collection: str) -> CollectionSummary: 

150 # Docstring inherited from a base class. 

151 return self._registry.getCollectionSummary(collection) 

152 

153 def registerDatasetType(self, datasetType: DatasetType) -> bool: 

154 # Docstring inherited from a base class. 

155 return self._registry.registerDatasetType(datasetType) 

156 

157 def removeDatasetType(self, name: str | tuple[str, ...]) -> None: 

158 # Docstring inherited from a base class. 

159 self._registry.removeDatasetType(name) 

160 

161 def getDatasetType(self, name: str) -> DatasetType: 

162 # Docstring inherited from a base class. 

163 return self._registry.getDatasetType(name) 

164 

165 def supportsIdGenerationMode(self, mode: DatasetIdGenEnum) -> bool: 

166 # Docstring inherited from a base class. 

167 return self._registry.supportsIdGenerationMode(mode) 

168 

169 def findDataset( 

170 self, 

171 datasetType: DatasetType | str, 

172 dataId: DataId | None = None, 

173 *, 

174 collections: CollectionArgType | None = None, 

175 timespan: Timespan | None = None, 

176 **kwargs: Any, 

177 ) -> DatasetRef | None: 

178 # Docstring inherited from a base class. 

179 return self._registry.findDataset( 

180 datasetType, dataId, collections=collections, timespan=timespan, **kwargs 

181 ) 

182 

183 def insertDatasets( 

184 self, 

185 datasetType: DatasetType | str, 

186 dataIds: Iterable[DataId], 

187 run: str | None = None, 

188 expand: bool = True, 

189 idGenerationMode: DatasetIdGenEnum = DatasetIdGenEnum.UNIQUE, 

190 ) -> list[DatasetRef]: 

191 # Docstring inherited from a base class. 

192 return self._registry.insertDatasets(datasetType, dataIds, run, expand, idGenerationMode) 

193 

194 def _importDatasets(self, datasets: Iterable[DatasetRef], expand: bool = True) -> list[DatasetRef]: 

195 # Docstring inherited from a base class. 

196 return self._registry._importDatasets(datasets, expand) 

197 

198 def getDataset(self, id: DatasetId) -> DatasetRef | None: 

199 # Docstring inherited from a base class. 

200 return self._registry.getDataset(id) 

201 

202 def removeDatasets(self, refs: Iterable[DatasetRef]) -> None: 

203 # Docstring inherited from a base class. 

204 self._registry.removeDatasets(refs) 

205 

206 def associate(self, collection: str, refs: Iterable[DatasetRef]) -> None: 

207 # Docstring inherited from a base class. 

208 self._registry.associate(collection, refs) 

209 

210 def disassociate(self, collection: str, refs: Iterable[DatasetRef]) -> None: 

211 # Docstring inherited from a base class. 

212 self._registry.disassociate(collection, refs) 

213 

214 def certify(self, collection: str, refs: Iterable[DatasetRef], timespan: Timespan) -> None: 

215 # Docstring inherited from a base class. 

216 self._registry.certify(collection, refs, timespan) 

217 

218 def decertify( 

219 self, 

220 collection: str, 

221 datasetType: str | DatasetType, 

222 timespan: Timespan, 

223 *, 

224 dataIds: Iterable[DataId] | None = None, 

225 ) -> None: 

226 # Docstring inherited from a base class. 

227 self._registry.decertify(collection, datasetType, timespan, dataIds=dataIds) 

228 

229 def getDatasetLocations(self, ref: DatasetRef) -> Iterable[str]: 

230 # Docstring inherited from a base class. 

231 return self._registry.getDatasetLocations(ref) 

232 

233 def expandDataId( 

234 self, 

235 dataId: DataId | None = None, 

236 *, 

237 graph: DimensionGraph | None = None, 

238 records: NameLookupMapping[DimensionElement, DimensionRecord | None] | None = None, 

239 withDefaults: bool = True, 

240 **kwargs: Any, 

241 ) -> DataCoordinate: 

242 # Docstring inherited from a base class. 

243 return self._registry.expandDataId( 

244 dataId, graph=graph, records=records, withDefaults=withDefaults, **kwargs 

245 ) 

246 

247 def insertDimensionData( 

248 self, 

249 element: DimensionElement | str, 

250 *data: Mapping[str, Any] | DimensionRecord, 

251 conform: bool = True, 

252 replace: bool = False, 

253 skip_existing: bool = False, 

254 ) -> None: 

255 # Docstring inherited from a base class. 

256 self._registry.insertDimensionData( 

257 element, *data, conform=conform, replace=replace, skip_existing=skip_existing 

258 ) 

259 

260 def syncDimensionData( 

261 self, 

262 element: DimensionElement | str, 

263 row: Mapping[str, Any] | DimensionRecord, 

264 conform: bool = True, 

265 update: bool = False, 

266 ) -> bool | dict[str, Any]: 

267 # Docstring inherited from a base class. 

268 return self._registry.syncDimensionData(element, row, conform, update) 

269 

270 def queryDatasetTypes( 

271 self, 

272 expression: Any = ..., 

273 *, 

274 components: bool | None = None, 

275 missing: list[str] | None = None, 

276 ) -> Iterable[DatasetType]: 

277 # Docstring inherited from a base class. 

278 return self._registry.queryDatasetTypes(expression, components=components, missing=missing) 

279 

280 def queryCollections( 

281 self, 

282 expression: Any = ..., 

283 datasetType: DatasetType | None = None, 

284 collectionTypes: Iterable[CollectionType] | CollectionType = CollectionType.all(), 

285 flattenChains: bool = False, 

286 includeChains: bool | None = None, 

287 ) -> Sequence[str]: 

288 # Docstring inherited from a base class. 

289 return self._registry.queryCollections( 

290 expression, datasetType, collectionTypes, flattenChains, includeChains 

291 ) 

292 

293 def queryDatasets( 

294 self, 

295 datasetType: Any, 

296 *, 

297 collections: CollectionArgType | None = None, 

298 dimensions: Iterable[Dimension | str] | None = None, 

299 dataId: DataId | None = None, 

300 where: str = "", 

301 findFirst: bool = False, 

302 components: bool | None = None, 

303 bind: Mapping[str, Any] | None = None, 

304 check: bool = True, 

305 **kwargs: Any, 

306 ) -> DatasetQueryResults: 

307 # Docstring inherited from a base class. 

308 return self._registry.queryDatasets( 

309 datasetType, 

310 collections=collections, 

311 dimensions=dimensions, 

312 dataId=dataId, 

313 where=where, 

314 findFirst=findFirst, 

315 components=components, 

316 bind=bind, 

317 check=check, 

318 **kwargs, 

319 ) 

320 

321 def queryDataIds( 

322 self, 

323 dimensions: Iterable[Dimension | str] | Dimension | str, 

324 *, 

325 dataId: DataId | None = None, 

326 datasets: Any = None, 

327 collections: CollectionArgType | None = None, 

328 where: str = "", 

329 components: bool | None = None, 

330 bind: Mapping[str, Any] | None = None, 

331 check: bool = True, 

332 **kwargs: Any, 

333 ) -> DataCoordinateQueryResults: 

334 # Docstring inherited from a base class. 

335 return self._registry.queryDataIds( 

336 dimensions, 

337 dataId=dataId, 

338 datasets=datasets, 

339 collections=collections, 

340 where=where, 

341 components=components, 

342 bind=bind, 

343 check=check, 

344 **kwargs, 

345 ) 

346 

347 def queryDimensionRecords( 

348 self, 

349 element: DimensionElement | str, 

350 *, 

351 dataId: DataId | None = None, 

352 datasets: Any = None, 

353 collections: CollectionArgType | None = None, 

354 where: str = "", 

355 components: bool | None = None, 

356 bind: Mapping[str, Any] | None = None, 

357 check: bool = True, 

358 **kwargs: Any, 

359 ) -> DimensionRecordQueryResults: 

360 # Docstring inherited from a base class. 

361 return self._registry.queryDimensionRecords( 

362 element, 

363 dataId=dataId, 

364 datasets=datasets, 

365 collections=collections, 

366 where=where, 

367 components=components, 

368 bind=bind, 

369 check=check, 

370 **kwargs, 

371 ) 

372 

373 def queryDatasetAssociations( 

374 self, 

375 datasetType: str | DatasetType, 

376 collections: CollectionArgType | None = ..., 

377 *, 

378 collectionTypes: Iterable[CollectionType] = CollectionType.all(), 

379 flattenChains: bool = False, 

380 ) -> Iterator[DatasetAssociation]: 

381 # Docstring inherited from a base class. 

382 return self._registry.queryDatasetAssociations( 

383 datasetType, 

384 collections, 

385 collectionTypes=collectionTypes, 

386 flattenChains=flattenChains, 

387 ) 

388 

389 @property 

390 def obsCoreTableManager(self) -> ObsCoreTableManager | None: 

391 # Docstring inherited from a base class. 

392 return self._registry.obsCoreTableManager