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

108 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-10-27 09:44 +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 software is dual licensed under the GNU General Public License and also 

10# under a 3-clause BSD license. Recipients may choose which of these licenses 

11# to use; please see the files gpl-3.0.txt and/or bsd_license.txt, 

12# respectively. If you choose the GPL option then the following text applies 

13# (but note that there is still no warranty even if you opt for BSD instead): 

14# 

15# This program is free software: you can redistribute it and/or modify 

16# it under the terms of the GNU General Public License as published by 

17# the Free Software Foundation, either version 3 of the License, or 

18# (at your option) any later version. 

19# 

20# This program is distributed in the hope that it will be useful, 

21# but WITHOUT ANY WARRANTY; without even the implied warranty of 

22# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

23# GNU General Public License for more details. 

24# 

25# You should have received a copy of the GNU General Public License 

26# along with this program. If not, see <http://www.gnu.org/licenses/>. 

27 

28from __future__ import annotations 

29 

30__all__ = ("Registry",) 

31 

32import contextlib 

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

34from typing import TYPE_CHECKING, Any 

35 

36from ._dataset_association import DatasetAssociation 

37from ._dataset_ref import DatasetId, DatasetIdGenEnum, DatasetRef 

38from ._dataset_type import DatasetType 

39from ._named import NameLookupMapping 

40from ._timespan import Timespan 

41from .dimensions import ( 

42 DataCoordinate, 

43 DataId, 

44 Dimension, 

45 DimensionElement, 

46 DimensionGraph, 

47 DimensionRecord, 

48 DimensionUniverse, 

49) 

50from .registry import Registry 

51from .registry._collection_summary import CollectionSummary 

52from .registry._collection_type import CollectionType 

53from .registry._defaults import RegistryDefaults 

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

55 

56if TYPE_CHECKING: 

57 from .direct_butler import DirectButler 

58 from .registry._registry import CollectionArgType 

59 from .registry.interfaces import ObsCoreTableManager 

60 

61 

62class RegistryShim(Registry): 

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

64 

65 Parameters 

66 ---------- 

67 butler : `DirectButler` 

68 Data butler instance. 

69 

70 Notes 

71 ----- 

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

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

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

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

76 """ 

77 

78 def __init__(self, butler: DirectButler): 

79 self._butler = butler 

80 self._registry = butler._registry 

81 

82 def isWriteable(self) -> bool: 

83 # Docstring inherited from a base class. 

84 return self._registry.isWriteable() 

85 

86 @property 

87 def dimensions(self) -> DimensionUniverse: 

88 # Docstring inherited from a base class. 

89 return self._registry.dimensions 

90 

91 @property 

92 def defaults(self) -> RegistryDefaults: 

93 # Docstring inherited from a base class. 

94 return self._registry.defaults 

95 

96 @defaults.setter 

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

98 # Docstring inherited from a base class. 

99 self._registry.defaults = value 

100 

101 def refresh(self) -> None: 

102 # Docstring inherited from a base class. 

103 self._registry.refresh() 

104 

105 @contextlib.contextmanager 

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

107 # Docstring inherited from a base class. 

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

109 yield 

110 

111 def resetConnectionPool(self) -> None: 

112 # Docstring inherited from a base class. 

113 self._registry.resetConnectionPool() 

114 

115 def registerCollection( 

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

117 ) -> bool: 

118 # Docstring inherited from a base class. 

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

120 

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

122 # Docstring inherited from a base class. 

123 return self._registry.getCollectionType(name) 

124 

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

126 # Docstring inherited from a base class. 

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

128 

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

130 # Docstring inherited from a base class. 

131 self._registry.removeCollection(name) 

132 

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

134 # Docstring inherited from a base class. 

135 return self._registry.getCollectionChain(parent) 

136 

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

138 # Docstring inherited from a base class. 

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

140 

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

142 # Docstring inherited from a base class. 

143 return self._registry.getCollectionParentChains(collection) 

144 

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

146 # Docstring inherited from a base class. 

147 return self._registry.getCollectionDocumentation(collection) 

148 

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

150 # Docstring inherited from a base class. 

151 self._registry.setCollectionDocumentation(collection, doc) 

152 

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

154 # Docstring inherited from a base class. 

155 return self._registry.getCollectionSummary(collection) 

156 

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

158 # Docstring inherited from a base class. 

159 return self._registry.registerDatasetType(datasetType) 

160 

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

162 # Docstring inherited from a base class. 

163 self._registry.removeDatasetType(name) 

164 

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

166 # Docstring inherited from a base class. 

167 return self._registry.getDatasetType(name) 

168 

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

170 # Docstring inherited from a base class. 

171 return self._registry.supportsIdGenerationMode(mode) 

172 

173 def findDataset( 

174 self, 

175 datasetType: DatasetType | str, 

176 dataId: DataId | None = None, 

177 *, 

178 collections: CollectionArgType | None = None, 

179 timespan: Timespan | None = None, 

180 **kwargs: Any, 

181 ) -> DatasetRef | None: 

182 # Docstring inherited from a base class. 

183 return self._registry.findDataset( 

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

185 ) 

186 

187 def insertDatasets( 

188 self, 

189 datasetType: DatasetType | str, 

190 dataIds: Iterable[DataId], 

191 run: str | None = None, 

192 expand: bool = True, 

193 idGenerationMode: DatasetIdGenEnum = DatasetIdGenEnum.UNIQUE, 

194 ) -> list[DatasetRef]: 

195 # Docstring inherited from a base class. 

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

197 

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

199 # Docstring inherited from a base class. 

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

201 

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

203 # Docstring inherited from a base class. 

204 return self._registry.getDataset(id) 

205 

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

207 # Docstring inherited from a base class. 

208 self._registry.removeDatasets(refs) 

209 

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

211 # Docstring inherited from a base class. 

212 self._registry.associate(collection, refs) 

213 

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

215 # Docstring inherited from a base class. 

216 self._registry.disassociate(collection, refs) 

217 

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

219 # Docstring inherited from a base class. 

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

221 

222 def decertify( 

223 self, 

224 collection: str, 

225 datasetType: str | DatasetType, 

226 timespan: Timespan, 

227 *, 

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

229 ) -> None: 

230 # Docstring inherited from a base class. 

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

232 

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

234 # Docstring inherited from a base class. 

235 return self._registry.getDatasetLocations(ref) 

236 

237 def expandDataId( 

238 self, 

239 dataId: DataId | None = None, 

240 *, 

241 graph: DimensionGraph | None = None, 

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

243 withDefaults: bool = True, 

244 **kwargs: Any, 

245 ) -> DataCoordinate: 

246 # Docstring inherited from a base class. 

247 return self._registry.expandDataId( 

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

249 ) 

250 

251 def insertDimensionData( 

252 self, 

253 element: DimensionElement | str, 

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

255 conform: bool = True, 

256 replace: bool = False, 

257 skip_existing: bool = False, 

258 ) -> None: 

259 # Docstring inherited from a base class. 

260 self._registry.insertDimensionData( 

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

262 ) 

263 

264 def syncDimensionData( 

265 self, 

266 element: DimensionElement | str, 

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

268 conform: bool = True, 

269 update: bool = False, 

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

271 # Docstring inherited from a base class. 

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

273 

274 def queryDatasetTypes( 

275 self, 

276 expression: Any = ..., 

277 *, 

278 components: bool | None = None, 

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

280 ) -> Iterable[DatasetType]: 

281 # Docstring inherited from a base class. 

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

283 

284 def queryCollections( 

285 self, 

286 expression: Any = ..., 

287 datasetType: DatasetType | None = None, 

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

289 flattenChains: bool = False, 

290 includeChains: bool | None = None, 

291 ) -> Sequence[str]: 

292 # Docstring inherited from a base class. 

293 return self._registry.queryCollections( 

294 expression, datasetType, collectionTypes, flattenChains, includeChains 

295 ) 

296 

297 def queryDatasets( 

298 self, 

299 datasetType: Any, 

300 *, 

301 collections: CollectionArgType | None = None, 

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

303 dataId: DataId | None = None, 

304 where: str = "", 

305 findFirst: bool = False, 

306 components: bool | None = None, 

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

308 check: bool = True, 

309 **kwargs: Any, 

310 ) -> DatasetQueryResults: 

311 # Docstring inherited from a base class. 

312 return self._registry.queryDatasets( 

313 datasetType, 

314 collections=collections, 

315 dimensions=dimensions, 

316 dataId=dataId, 

317 where=where, 

318 findFirst=findFirst, 

319 components=components, 

320 bind=bind, 

321 check=check, 

322 **kwargs, 

323 ) 

324 

325 def queryDataIds( 

326 self, 

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

328 *, 

329 dataId: DataId | None = None, 

330 datasets: Any = None, 

331 collections: CollectionArgType | None = None, 

332 where: str = "", 

333 components: bool | None = None, 

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

335 check: bool = True, 

336 **kwargs: Any, 

337 ) -> DataCoordinateQueryResults: 

338 # Docstring inherited from a base class. 

339 return self._registry.queryDataIds( 

340 dimensions, 

341 dataId=dataId, 

342 datasets=datasets, 

343 collections=collections, 

344 where=where, 

345 components=components, 

346 bind=bind, 

347 check=check, 

348 **kwargs, 

349 ) 

350 

351 def queryDimensionRecords( 

352 self, 

353 element: DimensionElement | str, 

354 *, 

355 dataId: DataId | None = None, 

356 datasets: Any = None, 

357 collections: CollectionArgType | None = None, 

358 where: str = "", 

359 components: bool | None = None, 

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

361 check: bool = True, 

362 **kwargs: Any, 

363 ) -> DimensionRecordQueryResults: 

364 # Docstring inherited from a base class. 

365 return self._registry.queryDimensionRecords( 

366 element, 

367 dataId=dataId, 

368 datasets=datasets, 

369 collections=collections, 

370 where=where, 

371 components=components, 

372 bind=bind, 

373 check=check, 

374 **kwargs, 

375 ) 

376 

377 def queryDatasetAssociations( 

378 self, 

379 datasetType: str | DatasetType, 

380 collections: CollectionArgType | None = ..., 

381 *, 

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

383 flattenChains: bool = False, 

384 ) -> Iterator[DatasetAssociation]: 

385 # Docstring inherited from a base class. 

386 return self._registry.queryDatasetAssociations( 

387 datasetType, 

388 collections, 

389 collectionTypes=collectionTypes, 

390 flattenChains=flattenChains, 

391 ) 

392 

393 @property 

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

395 # Docstring inherited from a base class. 

396 return self._registry.obsCoreTableManager