Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-39944: Replace Butler.registry with registry shim #864

Merged
merged 6 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 72 additions & 53 deletions python/lsst/daf/butler/_butler.py

Large diffs are not rendered by default.

392 changes: 392 additions & 0 deletions python/lsst/daf/butler/_registry_shim.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,392 @@
# This file is part of daf_butler.
#
# Developed for the LSST Data Management System.
# This product includes software developed by the LSST Project
# (http://www.lsst.org).
# See the COPYRIGHT file at the top-level directory of this distribution
# for details of code ownership.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from __future__ import annotations

__all__ = ("Registry",)

import contextlib
from collections.abc import Iterable, Iterator, Mapping, Sequence
from typing import TYPE_CHECKING, Any

from .core import (
DataCoordinate,
DataId,
DatasetAssociation,
DatasetId,
DatasetIdGenEnum,
DatasetRef,
DatasetType,
Dimension,
DimensionElement,
DimensionGraph,
DimensionRecord,
DimensionUniverse,
NameLookupMapping,
Timespan,
)
from .registry import Registry
from .registry._collection_summary import CollectionSummary
from .registry._collectionType import CollectionType
from .registry._defaults import RegistryDefaults
from .registry.queries import DataCoordinateQueryResults, DatasetQueryResults, DimensionRecordQueryResults

if TYPE_CHECKING:
from ._butler import Butler
from .registry._registry import CollectionArgType
from .registry.interfaces import ObsCoreTableManager


class RegistryShim(Registry):
"""Implementation of `Registry` interface exposed to clients by `Butler`.

Parameters
----------
butler : `Butler`
Data butler instance.

Notes
-----
This shim implementation of `Registry` forwards all methods to an actual
Registry instance which is internal to Butler or to Butler methods. Its
purpose is to provide a stable interface to many client-visible operations
while we perform re-structuring of Registry and Butler implementations.
"""

def __init__(self, butler: Butler):
self._butler = butler
self._registry = butler._registry

def isWriteable(self) -> bool:
# Docstring inherited from a base class.
return self._registry.isWriteable()

Check warning on line 80 in python/lsst/daf/butler/_registry_shim.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/_registry_shim.py#L80

Added line #L80 was not covered by tests

@property
def dimensions(self) -> DimensionUniverse:
# Docstring inherited from a base class.
return self._registry.dimensions

@property
def defaults(self) -> RegistryDefaults:
# Docstring inherited from a base class.
return self._registry.defaults

@defaults.setter
def defaults(self, value: RegistryDefaults) -> None:
# Docstring inherited from a base class.
self._registry.defaults = value

def refresh(self) -> None:
# Docstring inherited from a base class.
self._registry.refresh()

@contextlib.contextmanager
def transaction(self, *, savepoint: bool = False) -> Iterator[None]:
# Docstring inherited from a base class.
with self._registry.transaction(savepoint=savepoint):
yield

Check warning on line 105 in python/lsst/daf/butler/_registry_shim.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/_registry_shim.py#L105

Added line #L105 was not covered by tests

def resetConnectionPool(self) -> None:
# Docstring inherited from a base class.
self._registry.resetConnectionPool()

Check warning on line 109 in python/lsst/daf/butler/_registry_shim.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/_registry_shim.py#L109

Added line #L109 was not covered by tests

def registerCollection(
self, name: str, type: CollectionType = CollectionType.TAGGED, doc: str | None = None
) -> bool:
# Docstring inherited from a base class.
return self._registry.registerCollection(name, type, doc)

def getCollectionType(self, name: str) -> CollectionType:
# Docstring inherited from a base class.
return self._registry.getCollectionType(name)

def registerRun(self, name: str, doc: str | None = None) -> bool:
# Docstring inherited from a base class.
return self._registry.registerRun(name, doc)

def removeCollection(self, name: str) -> None:
# Docstring inherited from a base class.
self._registry.removeCollection(name)

def getCollectionChain(self, parent: str) -> Sequence[str]:
# Docstring inherited from a base class.
return self._registry.getCollectionChain(parent)

def setCollectionChain(self, parent: str, children: Any, *, flatten: bool = False) -> None:
# Docstring inherited from a base class.
self._registry.setCollectionChain(parent, children, flatten=flatten)

def getCollectionParentChains(self, collection: str) -> set[str]:
# Docstring inherited from a base class.
return self._registry.getCollectionParentChains(collection)

def getCollectionDocumentation(self, collection: str) -> str | None:
# Docstring inherited from a base class.
return self._registry.getCollectionDocumentation(collection)

def setCollectionDocumentation(self, collection: str, doc: str | None) -> None:
# Docstring inherited from a base class.
self._registry.setCollectionDocumentation(collection, doc)

Check warning on line 147 in python/lsst/daf/butler/_registry_shim.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/_registry_shim.py#L147

Added line #L147 was not covered by tests

def getCollectionSummary(self, collection: str) -> CollectionSummary:
# Docstring inherited from a base class.
return self._registry.getCollectionSummary(collection)

Check warning on line 151 in python/lsst/daf/butler/_registry_shim.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/_registry_shim.py#L151

Added line #L151 was not covered by tests

def registerDatasetType(self, datasetType: DatasetType) -> bool:
# Docstring inherited from a base class.
return self._registry.registerDatasetType(datasetType)

def removeDatasetType(self, name: str | tuple[str, ...]) -> None:
# Docstring inherited from a base class.
self._registry.removeDatasetType(name)

def getDatasetType(self, name: str) -> DatasetType:
# Docstring inherited from a base class.
return self._registry.getDatasetType(name)

def supportsIdGenerationMode(self, mode: DatasetIdGenEnum) -> bool:
# Docstring inherited from a base class.
return self._registry.supportsIdGenerationMode(mode)

Check warning on line 167 in python/lsst/daf/butler/_registry_shim.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/_registry_shim.py#L167

Added line #L167 was not covered by tests

def findDataset(
self,
datasetType: DatasetType | str,
dataId: DataId | None = None,
*,
collections: CollectionArgType | None = None,
timespan: Timespan | None = None,
**kwargs: Any,
) -> DatasetRef | None:
# Docstring inherited from a base class.
return self._registry.findDataset(
datasetType, dataId, collections=collections, timespan=timespan, **kwargs
)

def insertDatasets(
self,
datasetType: DatasetType | str,
dataIds: Iterable[DataId],
run: str | None = None,
expand: bool = True,
idGenerationMode: DatasetIdGenEnum = DatasetIdGenEnum.UNIQUE,
) -> list[DatasetRef]:
# Docstring inherited from a base class.
return self._registry.insertDatasets(datasetType, dataIds, run, expand, idGenerationMode)

def _importDatasets(self, datasets: Iterable[DatasetRef], expand: bool = True) -> list[DatasetRef]:
# Docstring inherited from a base class.
return self._registry._importDatasets(datasets, expand)

def getDataset(self, id: DatasetId) -> DatasetRef | None:
# Docstring inherited from a base class.
return self._registry.getDataset(id)

def removeDatasets(self, refs: Iterable[DatasetRef]) -> None:
# Docstring inherited from a base class.
self._registry.removeDatasets(refs)

Check warning on line 204 in python/lsst/daf/butler/_registry_shim.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/_registry_shim.py#L204

Added line #L204 was not covered by tests

def associate(self, collection: str, refs: Iterable[DatasetRef]) -> None:
# Docstring inherited from a base class.
self._registry.associate(collection, refs)

def disassociate(self, collection: str, refs: Iterable[DatasetRef]) -> None:
# Docstring inherited from a base class.
self._registry.disassociate(collection, refs)

Check warning on line 212 in python/lsst/daf/butler/_registry_shim.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/_registry_shim.py#L212

Added line #L212 was not covered by tests

def certify(self, collection: str, refs: Iterable[DatasetRef], timespan: Timespan) -> None:
# Docstring inherited from a base class.
self._registry.certify(collection, refs, timespan)

def decertify(
self,
collection: str,
datasetType: str | DatasetType,
timespan: Timespan,
*,
dataIds: Iterable[DataId] | None = None,
) -> None:
# Docstring inherited from a base class.
self._registry.decertify(collection, datasetType, timespan, dataIds=dataIds)

Check warning on line 227 in python/lsst/daf/butler/_registry_shim.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/_registry_shim.py#L227

Added line #L227 was not covered by tests

def getDatasetLocations(self, ref: DatasetRef) -> Iterable[str]:
# Docstring inherited from a base class.
return self._registry.getDatasetLocations(ref)

def expandDataId(
self,
dataId: DataId | None = None,
*,
graph: DimensionGraph | None = None,
records: NameLookupMapping[DimensionElement, DimensionRecord | None] | None = None,
withDefaults: bool = True,
**kwargs: Any,
) -> DataCoordinate:
# Docstring inherited from a base class.
return self._registry.expandDataId(
dataId, graph=graph, records=records, withDefaults=withDefaults, **kwargs
)

def insertDimensionData(
self,
element: DimensionElement | str,
*data: Mapping[str, Any] | DimensionRecord,
conform: bool = True,
replace: bool = False,
skip_existing: bool = False,
) -> None:
# Docstring inherited from a base class.
self._registry.insertDimensionData(
element, *data, conform=conform, replace=replace, skip_existing=skip_existing
)

def syncDimensionData(
self,
element: DimensionElement | str,
row: Mapping[str, Any] | DimensionRecord,
conform: bool = True,
update: bool = False,
) -> bool | dict[str, Any]:
# Docstring inherited from a base class.
return self._registry.syncDimensionData(element, row, conform, update)

def queryDatasetTypes(
self,
expression: Any = ...,
*,
components: bool | None = None,
missing: list[str] | None = None,
) -> Iterable[DatasetType]:
# Docstring inherited from a base class.
return self._registry.queryDatasetTypes(expression, components=components, missing=missing)

def queryCollections(
self,
expression: Any = ...,
datasetType: DatasetType | None = None,
collectionTypes: Iterable[CollectionType] | CollectionType = CollectionType.all(),
flattenChains: bool = False,
includeChains: bool | None = None,
) -> Sequence[str]:
# Docstring inherited from a base class.
return self._registry.queryCollections(
expression, datasetType, collectionTypes, flattenChains, includeChains
)

def queryDatasets(
self,
datasetType: Any,
*,
collections: CollectionArgType | None = None,
dimensions: Iterable[Dimension | str] | None = None,
dataId: DataId | None = None,
where: str = "",
findFirst: bool = False,
components: bool | None = None,
bind: Mapping[str, Any] | None = None,
check: bool = True,
**kwargs: Any,
) -> DatasetQueryResults:
# Docstring inherited from a base class.
return self._registry.queryDatasets(
datasetType,
collections=collections,
dimensions=dimensions,
dataId=dataId,
where=where,
findFirst=findFirst,
components=components,
bind=bind,
check=check,
**kwargs,
)

def queryDataIds(
self,
dimensions: Iterable[Dimension | str] | Dimension | str,
*,
dataId: DataId | None = None,
datasets: Any = None,
collections: CollectionArgType | None = None,
where: str = "",
components: bool | None = None,
bind: Mapping[str, Any] | None = None,
check: bool = True,
**kwargs: Any,
) -> DataCoordinateQueryResults:
# Docstring inherited from a base class.
return self._registry.queryDataIds(
dimensions,
dataId=dataId,
datasets=datasets,
collections=collections,
where=where,
components=components,
bind=bind,
check=check,
**kwargs,
)

def queryDimensionRecords(
self,
element: DimensionElement | str,
*,
dataId: DataId | None = None,
datasets: Any = None,
collections: CollectionArgType | None = None,
where: str = "",
components: bool | None = None,
bind: Mapping[str, Any] | None = None,
check: bool = True,
**kwargs: Any,
) -> DimensionRecordQueryResults:
# Docstring inherited from a base class.
return self._registry.queryDimensionRecords(
element,
dataId=dataId,
datasets=datasets,
collections=collections,
where=where,
components=components,
bind=bind,
check=check,
**kwargs,
)

def queryDatasetAssociations(
self,
datasetType: str | DatasetType,
collections: CollectionArgType | None = ...,
*,
collectionTypes: Iterable[CollectionType] = CollectionType.all(),
flattenChains: bool = False,
) -> Iterator[DatasetAssociation]:
# Docstring inherited from a base class.
return self._registry.queryDatasetAssociations(
datasetType,
collections,
collectionTypes=collectionTypes,
flattenChains=flattenChains,
)

@property
def obsCoreTableManager(self) -> ObsCoreTableManager | None:
# Docstring inherited from a base class.
return self._registry.obsCoreTableManager

Check warning on line 392 in python/lsst/daf/butler/_registry_shim.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/_registry_shim.py#L392

Added line #L392 was not covered by tests
Loading
Loading