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

103 statements  

« prev     ^ index     » next       coverage.py v7.3.1, created at 2023-10-02 08:00 +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 .core import ( 

37 DataCoordinate, 

38 DataId, 

39 DatasetAssociation, 

40 DatasetId, 

41 DatasetIdGenEnum, 

42 DatasetRef, 

43 DatasetType, 

44 Dimension, 

45 DimensionElement, 

46 DimensionGraph, 

47 DimensionRecord, 

48 DimensionUniverse, 

49 NameLookupMapping, 

50 Timespan, 

51) 

52from .registry import Registry 

53from .registry._collection_summary import CollectionSummary 

54from .registry._collectionType import CollectionType 

55from .registry._defaults import RegistryDefaults 

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

57 

58if TYPE_CHECKING: 

59 from ._butler import Butler 

60 from .registry._registry import CollectionArgType 

61 from .registry.interfaces import ObsCoreTableManager 

62 

63 

64class RegistryShim(Registry): 

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

66 

67 Parameters 

68 ---------- 

69 butler : `Butler` 

70 Data butler instance. 

71 

72 Notes 

73 ----- 

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

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

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

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

78 """ 

79 

80 def __init__(self, butler: Butler): 

81 self._butler = butler 

82 self._registry = butler._registry 

83 

84 def isWriteable(self) -> bool: 

85 # Docstring inherited from a base class. 

86 return self._registry.isWriteable() 

87 

88 @property 

89 def dimensions(self) -> DimensionUniverse: 

90 # Docstring inherited from a base class. 

91 return self._registry.dimensions 

92 

93 @property 

94 def defaults(self) -> RegistryDefaults: 

95 # Docstring inherited from a base class. 

96 return self._registry.defaults 

97 

98 @defaults.setter 

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

100 # Docstring inherited from a base class. 

101 self._registry.defaults = value 

102 

103 def refresh(self) -> None: 

104 # Docstring inherited from a base class. 

105 self._registry.refresh() 

106 

107 @contextlib.contextmanager 

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

109 # Docstring inherited from a base class. 

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

111 yield 

112 

113 def resetConnectionPool(self) -> None: 

114 # Docstring inherited from a base class. 

115 self._registry.resetConnectionPool() 

116 

117 def registerCollection( 

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

119 ) -> bool: 

120 # Docstring inherited from a base class. 

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

122 

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

124 # Docstring inherited from a base class. 

125 return self._registry.getCollectionType(name) 

126 

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

128 # Docstring inherited from a base class. 

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

130 

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

132 # Docstring inherited from a base class. 

133 self._registry.removeCollection(name) 

134 

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

136 # Docstring inherited from a base class. 

137 return self._registry.getCollectionChain(parent) 

138 

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

140 # Docstring inherited from a base class. 

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

142 

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

144 # Docstring inherited from a base class. 

145 return self._registry.getCollectionParentChains(collection) 

146 

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

148 # Docstring inherited from a base class. 

149 return self._registry.getCollectionDocumentation(collection) 

150 

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

152 # Docstring inherited from a base class. 

153 self._registry.setCollectionDocumentation(collection, doc) 

154 

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

156 # Docstring inherited from a base class. 

157 return self._registry.getCollectionSummary(collection) 

158 

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

160 # Docstring inherited from a base class. 

161 return self._registry.registerDatasetType(datasetType) 

162 

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

164 # Docstring inherited from a base class. 

165 self._registry.removeDatasetType(name) 

166 

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

168 # Docstring inherited from a base class. 

169 return self._registry.getDatasetType(name) 

170 

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

172 # Docstring inherited from a base class. 

173 return self._registry.supportsIdGenerationMode(mode) 

174 

175 def findDataset( 

176 self, 

177 datasetType: DatasetType | str, 

178 dataId: DataId | None = None, 

179 *, 

180 collections: CollectionArgType | None = None, 

181 timespan: Timespan | None = None, 

182 **kwargs: Any, 

183 ) -> DatasetRef | None: 

184 # Docstring inherited from a base class. 

185 return self._registry.findDataset( 

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

187 ) 

188 

189 def insertDatasets( 

190 self, 

191 datasetType: DatasetType | str, 

192 dataIds: Iterable[DataId], 

193 run: str | None = None, 

194 expand: bool = True, 

195 idGenerationMode: DatasetIdGenEnum = DatasetIdGenEnum.UNIQUE, 

196 ) -> list[DatasetRef]: 

197 # Docstring inherited from a base class. 

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

199 

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

201 # Docstring inherited from a base class. 

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

203 

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

205 # Docstring inherited from a base class. 

206 return self._registry.getDataset(id) 

207 

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

209 # Docstring inherited from a base class. 

210 self._registry.removeDatasets(refs) 

211 

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

213 # Docstring inherited from a base class. 

214 self._registry.associate(collection, refs) 

215 

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

217 # Docstring inherited from a base class. 

218 self._registry.disassociate(collection, refs) 

219 

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

221 # Docstring inherited from a base class. 

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

223 

224 def decertify( 

225 self, 

226 collection: str, 

227 datasetType: str | DatasetType, 

228 timespan: Timespan, 

229 *, 

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

231 ) -> None: 

232 # Docstring inherited from a base class. 

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

234 

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

236 # Docstring inherited from a base class. 

237 return self._registry.getDatasetLocations(ref) 

238 

239 def expandDataId( 

240 self, 

241 dataId: DataId | None = None, 

242 *, 

243 graph: DimensionGraph | None = None, 

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

245 withDefaults: bool = True, 

246 **kwargs: Any, 

247 ) -> DataCoordinate: 

248 # Docstring inherited from a base class. 

249 return self._registry.expandDataId( 

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

251 ) 

252 

253 def insertDimensionData( 

254 self, 

255 element: DimensionElement | str, 

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

257 conform: bool = True, 

258 replace: bool = False, 

259 skip_existing: bool = False, 

260 ) -> None: 

261 # Docstring inherited from a base class. 

262 self._registry.insertDimensionData( 

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

264 ) 

265 

266 def syncDimensionData( 

267 self, 

268 element: DimensionElement | str, 

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

270 conform: bool = True, 

271 update: bool = False, 

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

273 # Docstring inherited from a base class. 

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

275 

276 def queryDatasetTypes( 

277 self, 

278 expression: Any = ..., 

279 *, 

280 components: bool | None = None, 

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

282 ) -> Iterable[DatasetType]: 

283 # Docstring inherited from a base class. 

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

285 

286 def queryCollections( 

287 self, 

288 expression: Any = ..., 

289 datasetType: DatasetType | None = None, 

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

291 flattenChains: bool = False, 

292 includeChains: bool | None = None, 

293 ) -> Sequence[str]: 

294 # Docstring inherited from a base class. 

295 return self._registry.queryCollections( 

296 expression, datasetType, collectionTypes, flattenChains, includeChains 

297 ) 

298 

299 def queryDatasets( 

300 self, 

301 datasetType: Any, 

302 *, 

303 collections: CollectionArgType | None = None, 

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

305 dataId: DataId | None = None, 

306 where: str = "", 

307 findFirst: bool = False, 

308 components: bool | None = None, 

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

310 check: bool = True, 

311 **kwargs: Any, 

312 ) -> DatasetQueryResults: 

313 # Docstring inherited from a base class. 

314 return self._registry.queryDatasets( 

315 datasetType, 

316 collections=collections, 

317 dimensions=dimensions, 

318 dataId=dataId, 

319 where=where, 

320 findFirst=findFirst, 

321 components=components, 

322 bind=bind, 

323 check=check, 

324 **kwargs, 

325 ) 

326 

327 def queryDataIds( 

328 self, 

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

330 *, 

331 dataId: DataId | None = None, 

332 datasets: Any = None, 

333 collections: CollectionArgType | None = None, 

334 where: str = "", 

335 components: bool | None = None, 

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

337 check: bool = True, 

338 **kwargs: Any, 

339 ) -> DataCoordinateQueryResults: 

340 # Docstring inherited from a base class. 

341 return self._registry.queryDataIds( 

342 dimensions, 

343 dataId=dataId, 

344 datasets=datasets, 

345 collections=collections, 

346 where=where, 

347 components=components, 

348 bind=bind, 

349 check=check, 

350 **kwargs, 

351 ) 

352 

353 def queryDimensionRecords( 

354 self, 

355 element: DimensionElement | str, 

356 *, 

357 dataId: DataId | None = None, 

358 datasets: Any = None, 

359 collections: CollectionArgType | None = None, 

360 where: str = "", 

361 components: bool | None = None, 

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

363 check: bool = True, 

364 **kwargs: Any, 

365 ) -> DimensionRecordQueryResults: 

366 # Docstring inherited from a base class. 

367 return self._registry.queryDimensionRecords( 

368 element, 

369 dataId=dataId, 

370 datasets=datasets, 

371 collections=collections, 

372 where=where, 

373 components=components, 

374 bind=bind, 

375 check=check, 

376 **kwargs, 

377 ) 

378 

379 def queryDatasetAssociations( 

380 self, 

381 datasetType: str | DatasetType, 

382 collections: CollectionArgType | None = ..., 

383 *, 

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

385 flattenChains: bool = False, 

386 ) -> Iterator[DatasetAssociation]: 

387 # Docstring inherited from a base class. 

388 return self._registry.queryDatasetAssociations( 

389 datasetType, 

390 collections, 

391 collectionTypes=collectionTypes, 

392 flattenChains=flattenChains, 

393 ) 

394 

395 @property 

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

397 # Docstring inherited from a base class. 

398 return self._registry.obsCoreTableManager