From 6e3cf8a16eaa36658bd3d78c79839f8fc9e0657f Mon Sep 17 00:00:00 2001 From: Andy Salnikov Date: Thu, 13 Jul 2023 15:04:25 -0700 Subject: [PATCH] Rename ButlerRegistry to _ButlerRegistry --- python/lsst/daf/butler/_butler.py | 6 ++-- python/lsst/daf/butler/registries/remote.py | 14 ++++---- python/lsst/daf/butler/registries/sql.py | 10 +++--- python/lsst/daf/butler/registry/__init__.py | 2 +- .../daf/butler/registry/_butler_registry.py | 34 +++++++++---------- .../daf/butler/registry/_registry_factory.py | 22 ++++++------ .../lsst/daf/butler/tests/_datasetsHelper.py | 4 +-- python/lsst/daf/butler/transfers/_context.py | 6 ++-- tests/test_obscore.py | 4 +-- tests/test_postgresql.py | 4 +-- tests/test_sqlite.py | 6 ++-- 11 files changed, 56 insertions(+), 56 deletions(-) diff --git a/python/lsst/daf/butler/_butler.py b/python/lsst/daf/butler/_butler.py index 34b7ab5109..0ff8fe74b5 100644 --- a/python/lsst/daf/butler/_butler.py +++ b/python/lsst/daf/butler/_butler.py @@ -78,7 +78,6 @@ from .core.repoRelocation import BUTLER_ROOT_TAG from .core.utils import transactional from .registry import ( - ButlerRegistry, CollectionType, ConflictingDefinitionError, DataIdError, @@ -88,6 +87,7 @@ RegistryConfig, RegistryDefaults, RegistryFactory, + _ButlerRegistry, ) from .transfers import RepoExportContext @@ -2649,9 +2649,9 @@ def dimensions(self) -> DimensionUniverse: # Docstring inherited. return self._registry.dimensions - _registry: ButlerRegistry + _registry: _ButlerRegistry """The object that manages dataset metadata and relationships - (`ButlerRegistry`). + (`_ButlerRegistry`). Most operations that don't involve reading or writing butler datasets are accessible only via `Registry` methods. diff --git a/python/lsst/daf/butler/registries/remote.py b/python/lsst/daf/butler/registries/remote.py index fbb93cc34e..f9f4959b6f 100644 --- a/python/lsst/daf/butler/registries/remote.py +++ b/python/lsst/daf/butler/registries/remote.py @@ -65,7 +65,7 @@ QueryDatasetsModel, QueryDimensionRecordsModel, ) -from ..registry import ButlerRegistry, CollectionSummary, CollectionType, RegistryConfig, RegistryDefaults +from ..registry import CollectionSummary, CollectionType, RegistryConfig, RegistryDefaults, _ButlerRegistry if TYPE_CHECKING: from .._butlerConfig import ButlerConfig @@ -73,7 +73,7 @@ from ..registry.interfaces import CollectionRecord, DatastoreRegistryBridgeManager -class RemoteRegistry(ButlerRegistry): +class RemoteRegistry(_ButlerRegistry): """Registry that can talk to a remote Butler server. Parameters @@ -91,8 +91,8 @@ def createFromConfig( config: RegistryConfig | str | None = None, dimensionConfig: DimensionConfig | str | None = None, butlerRoot: ResourcePathExpression | None = None, - ) -> ButlerRegistry: - """Create registry database and return `ButlerRegistry` instance. + ) -> _ButlerRegistry: + """Create registry database and return `_ButlerRegistry` instance. A remote registry can not create a registry database. Calling this method will raise an exception. @@ -106,7 +106,7 @@ def fromConfig( butlerRoot: ResourcePathExpression | None = None, writeable: bool = True, defaults: RegistryDefaults | None = None, - ) -> ButlerRegistry: + ) -> _ButlerRegistry: # Docstring inherited from lsst.daf.butler.registry.Registry config = cls.forceRegistryConfig(config) config.replaceRoot(butlerRoot) @@ -162,8 +162,8 @@ def isWriteable(self) -> bool: # Can be used to prevent any PUTs to server return self._writeable - def copy(self, defaults: RegistryDefaults | None = None) -> ButlerRegistry: - # Docstring inherited from lsst.daf.butler.registry.ButlerRegistry + def copy(self, defaults: RegistryDefaults | None = None) -> _ButlerRegistry: + # Docstring inherited from lsst.daf.butler.registry._ButlerRegistry if defaults is None: # No need to copy, because `RegistryDefaults` is immutable; we # effectively copy on write. diff --git a/python/lsst/daf/butler/registries/sql.py b/python/lsst/daf/butler/registries/sql.py index 04c987be76..dc112eeafb 100644 --- a/python/lsst/daf/butler/registries/sql.py +++ b/python/lsst/daf/butler/registries/sql.py @@ -61,7 +61,6 @@ from ..core.utils import transactional from ..registry import ( ArgumentError, - ButlerRegistry, CollectionExpressionError, CollectionSummary, CollectionType, @@ -76,6 +75,7 @@ RegistryConfig, RegistryConsistencyError, RegistryDefaults, + _ButlerRegistry, queries, ) from ..registry.interfaces import ChainedCollectionRecord, RunRecord @@ -96,7 +96,7 @@ _LOG = logging.getLogger(__name__) -class SqlRegistry(ButlerRegistry): +class SqlRegistry(_ButlerRegistry): """Registry implementation based on SQLAlchemy. Parameters @@ -121,7 +121,7 @@ def createFromConfig( config: RegistryConfig | str | None = None, dimensionConfig: DimensionConfig | str | None = None, butlerRoot: ResourcePathExpression | None = None, - ) -> ButlerRegistry: + ) -> _ButlerRegistry: """Create registry database and return `SqlRegistry` instance. This method initializes database contents, database must be empty @@ -168,7 +168,7 @@ def fromConfig( butlerRoot: ResourcePathExpression | None = None, writeable: bool = True, defaults: RegistryDefaults | None = None, - ) -> ButlerRegistry: + ) -> _ButlerRegistry: """Create `Registry` subclass instance from `config`. Registry database must be initialized prior to calling this method. @@ -225,7 +225,7 @@ def isWriteable(self) -> bool: # Docstring inherited from lsst.daf.butler.registry.Registry return self._db.isWriteable() - def copy(self, defaults: RegistryDefaults | None = None) -> ButlerRegistry: + def copy(self, defaults: RegistryDefaults | None = None) -> _ButlerRegistry: # Docstring inherited from lsst.daf.butler.registry.Registry if defaults is None: # No need to copy, because `RegistryDefaults` is immutable; we diff --git a/python/lsst/daf/butler/registry/__init__.py b/python/lsst/daf/butler/registry/__init__.py index 6151e93c24..c5819d0a24 100644 --- a/python/lsst/daf/butler/registry/__init__.py +++ b/python/lsst/daf/butler/registry/__init__.py @@ -20,7 +20,7 @@ # along with this program. If not, see . from . import interfaces, managers, queries, wildcards -from ._butler_registry import ButlerRegistry +from ._butler_registry import _ButlerRegistry from ._collection_summary import * from ._collectionType import * from ._config import * diff --git a/python/lsst/daf/butler/registry/_butler_registry.py b/python/lsst/daf/butler/registry/_butler_registry.py index 8a6d3bb633..f0150f320e 100644 --- a/python/lsst/daf/butler/registry/_butler_registry.py +++ b/python/lsst/daf/butler/registry/_butler_registry.py @@ -21,7 +21,7 @@ from __future__ import annotations -__all__ = ("ButlerRegistry",) +__all__ = ("_ButlerRegistry",) from abc import abstractmethod from typing import TYPE_CHECKING @@ -38,7 +38,7 @@ from .interfaces import CollectionRecord, DatastoreRegistryBridgeManager -class ButlerRegistry(Registry): +class _ButlerRegistry(Registry): """Registry interface extended with methods used by Butler implementation. Each registry implementation can have its own constructor parameters. @@ -84,8 +84,8 @@ def createFromConfig( config: RegistryConfig | str | None = None, dimensionConfig: DimensionConfig | str | None = None, butlerRoot: ResourcePathExpression | None = None, - ) -> ButlerRegistry: - """Create registry database and return `ButlerRegistry` instance. + ) -> _ButlerRegistry: + """Create registry database and return `_ButlerRegistry` instance. This method initializes database contents, database must be empty prior to calling this method. @@ -103,12 +103,12 @@ def createFromConfig( Returns ------- - registry : `ButlerRegistry` - A new `ButlerRegistry` instance. + registry : `_ButlerRegistry` + A new `_ButlerRegistry` instance. Notes ----- - This class will determine the concrete `ButlerRegistry` subclass to + This class will determine the concrete `_ButlerRegistry` subclass to use from configuration. Each subclass should implement this method even if it can not create a registry. """ @@ -122,8 +122,8 @@ def fromConfig( butlerRoot: ResourcePathExpression | None = None, writeable: bool = True, defaults: RegistryDefaults | None = None, - ) -> ButlerRegistry: - """Create `ButlerRegistry` subclass instance from ``config``. + ) -> _ButlerRegistry: + """Create `_ButlerRegistry` subclass instance from ``config``. Registry database must be initialized prior to calling this method. @@ -141,12 +141,12 @@ def fromConfig( Returns ------- - registry : `ButlerRegistry` (subclass) - A new `ButlerRegistry` subclass instance. + registry : `_ButlerRegistry` (subclass) + A new `_ButlerRegistry` subclass instance. Notes ----- - This class will determine the concrete `ButlerRegistry` subclass to + This class will determine the concrete `_ButlerRegistry` subclass to use from configuration. Each subclass should implement this method. """ # The base class implementation should trampoline to the correct @@ -156,9 +156,9 @@ def fromConfig( raise NotImplementedError() @abstractmethod - def copy(self, defaults: RegistryDefaults | None = None) -> ButlerRegistry: - """Create a new `ButlerRegistry` backed by the same data repository and - connection as this one, but independent defaults. + def copy(self, defaults: RegistryDefaults | None = None) -> _ButlerRegistry: + """Create a new `_ButlerRegistry` backed by the same data repository + and connection as this one, but independent defaults. Parameters ---------- @@ -169,8 +169,8 @@ def copy(self, defaults: RegistryDefaults | None = None) -> ButlerRegistry: Returns ------- - copy : `ButlerRegistry` - A new `ButlerRegistry` instance with its own defaults. + copy : `_ButlerRegistry` + A new `_ButlerRegistry` instance with its own defaults. Notes ----- diff --git a/python/lsst/daf/butler/registry/_registry_factory.py b/python/lsst/daf/butler/registry/_registry_factory.py index 0f54c9545c..9f2c727820 100644 --- a/python/lsst/daf/butler/registry/_registry_factory.py +++ b/python/lsst/daf/butler/registry/_registry_factory.py @@ -29,7 +29,7 @@ from lsst.utils import doImportType from ..core import Config, DimensionConfig -from ._butler_registry import ButlerRegistry +from ._butler_registry import _ButlerRegistry from ._config import RegistryConfig from ._defaults import RegistryDefaults @@ -69,9 +69,9 @@ def __init__(self, config: ButlerConfig | RegistryConfig | Config | str | None): # Default to the standard registry registry_cls_name = config.get("cls", "lsst.daf.butler.registries.sql.SqlRegistry") registry_cls = doImportType(registry_cls_name) - if not issubclass(registry_cls, ButlerRegistry): + if not issubclass(registry_cls, _ButlerRegistry): raise TypeError( - f"Registry class obtained from config {registry_cls_name} is not a ButlerRegistry class." + f"Registry class obtained from config {registry_cls_name} is not a _ButlerRegistry class." ) self._registry_cls = registry_cls @@ -79,8 +79,8 @@ def create_from_config( self, dimensionConfig: DimensionConfig | str | None = None, butlerRoot: ResourcePathExpression | None = None, - ) -> ButlerRegistry: - """Create registry database and return `ButlerRegistry` instance. + ) -> _ButlerRegistry: + """Create registry database and return `_ButlerRegistry` instance. This method initializes database contents, database must be empty prior to calling this method. @@ -95,8 +95,8 @@ def create_from_config( Returns ------- - registry : `ButlerRegistry` - A new `ButlerRegistry` instance. + registry : `_ButlerRegistry` + A new `_ButlerRegistry` instance. """ return self._registry_cls.createFromConfig(self._config, dimensionConfig, butlerRoot) @@ -105,8 +105,8 @@ def from_config( butlerRoot: ResourcePathExpression | None = None, writeable: bool = True, defaults: RegistryDefaults | None = None, - ) -> ButlerRegistry: - """Create `ButlerRegistry` subclass instance from ``config``. + ) -> _ButlerRegistry: + """Create `_ButlerRegistry` subclass instance from ``config``. Registry database must be initialized prior to calling this method. @@ -122,7 +122,7 @@ def from_config( Returns ------- - registry : `ButlerRegistry` (subclass) - A new `ButlerRegistry` subclass instance. + registry : `_ButlerRegistry` (subclass) + A new `_ButlerRegistry` subclass instance. """ return self._registry_cls.fromConfig(self._config, butlerRoot, writeable, defaults) diff --git a/python/lsst/daf/butler/tests/_datasetsHelper.py b/python/lsst/daf/butler/tests/_datasetsHelper.py index 562cdc2b70..c7be535714 100644 --- a/python/lsst/daf/butler/tests/_datasetsHelper.py +++ b/python/lsst/daf/butler/tests/_datasetsHelper.py @@ -38,7 +38,7 @@ if TYPE_CHECKING: from lsst.daf.butler import Config, DatasetId, Datastore, Dimension, DimensionGraph - from lsst.daf.butler.registry import ButlerRegistry + from lsst.daf.butler.registry import _ButlerRegistry class DatasetTestHelper: @@ -102,7 +102,7 @@ class DatastoreTestHelper: datastoreType: type[Datastore] configFile: str - def setUpDatastoreTests(self, registryClass: type[ButlerRegistry], configClass: type[Config]) -> None: + def setUpDatastoreTests(self, registryClass: type[_ButlerRegistry], configClass: type[Config]) -> None: """Shared setUp code for all Datastore tests.""" self.registry = registryClass() self.config = configClass(self.configFile) diff --git a/python/lsst/daf/butler/transfers/_context.py b/python/lsst/daf/butler/transfers/_context.py index aadc0f1445..8e71516316 100644 --- a/python/lsst/daf/butler/transfers/_context.py +++ b/python/lsst/daf/butler/transfers/_context.py @@ -38,7 +38,7 @@ DimensionRecord, FileDataset, ) -from ..registry import ButlerRegistry, CollectionType +from ..registry import CollectionType, _ButlerRegistry from ..registry.interfaces import ChainedCollectionRecord, CollectionRecord from ._interfaces import RepoExportBackend @@ -58,7 +58,7 @@ class RepoExportContext: Parameters ---------- - registry : `ButlerRegistry` + registry : `_ButlerRegistry` Registry to export from. datastore : `Datastore` Datastore to export from. @@ -73,7 +73,7 @@ class RepoExportContext: def __init__( self, - registry: ButlerRegistry, + registry: _ButlerRegistry, datastore: Datastore, backend: RepoExportBackend, *, diff --git a/tests/test_obscore.py b/tests/test_obscore.py index 04890b6abd..d1ef99a2d5 100644 --- a/tests/test_obscore.py +++ b/tests/test_obscore.py @@ -38,7 +38,7 @@ StorageClassFactory, ) from lsst.daf.butler.registries.sql import SqlRegistry -from lsst.daf.butler.registry import ButlerRegistry, Registry, RegistryConfig, RegistryFactory +from lsst.daf.butler.registry import Registry, RegistryConfig, RegistryFactory, _ButlerRegistry from lsst.daf.butler.registry.obscore import ( DatasetTypeConfig, ObsCoreConfig, @@ -64,7 +64,7 @@ class ObsCoreTests(TestCaseMixin): def make_registry( self, collections: list[str] | None = None, collection_type: str | None = None - ) -> ButlerRegistry: + ) -> _ButlerRegistry: """Create new empty Registry.""" config = self.make_registry_config(collections, collection_type) registry = RegistryFactory(config).create_from_config(butlerRoot=self.root) diff --git a/tests/test_postgresql.py b/tests/test_postgresql.py index 7bcad02ac0..c56dcc309a 100644 --- a/tests/test_postgresql.py +++ b/tests/test_postgresql.py @@ -40,7 +40,7 @@ import sqlalchemy from lsst.daf.butler import Timespan, ddl -from lsst.daf.butler.registry import ButlerRegistry, RegistryFactory +from lsst.daf.butler.registry import RegistryFactory, _ButlerRegistry from lsst.daf.butler.registry.databases.postgresql import PostgresqlDatabase, _RangeTimespanType from lsst.daf.butler.registry.tests import DatabaseTests, RegistryTests from lsst.daf.butler.tests.utils import makeTestTempDir, removeTestTempDir @@ -236,7 +236,7 @@ def tearDownClass(cls): def getDataDir(cls) -> str: return os.path.normpath(os.path.join(os.path.dirname(__file__), "data", "registry")) - def makeRegistry(self, share_repo_with: ButlerRegistry | None = None) -> ButlerRegistry: + def makeRegistry(self, share_repo_with: _ButlerRegistry | None = None) -> _ButlerRegistry: if share_repo_with is None: namespace = f"namespace_{secrets.token_hex(8).lower()}" else: diff --git a/tests/test_sqlite.py b/tests/test_sqlite.py index ae1fa8ccfa..386ba1e6fd 100644 --- a/tests/test_sqlite.py +++ b/tests/test_sqlite.py @@ -28,7 +28,7 @@ import sqlalchemy from lsst.daf.butler import ddl -from lsst.daf.butler.registry import ButlerRegistry, RegistryFactory +from lsst.daf.butler.registry import RegistryFactory, _ButlerRegistry from lsst.daf.butler.registry.databases.sqlite import SqliteDatabase from lsst.daf.butler.registry.tests import DatabaseTests, RegistryTests from lsst.daf.butler.tests.utils import makeTestTempDir, removeTestTempDir @@ -196,7 +196,7 @@ def tearDown(self): def getDataDir(cls) -> str: return os.path.normpath(os.path.join(os.path.dirname(__file__), "data", "registry")) - def makeRegistry(self, share_repo_with: ButlerRegistry | None = None) -> ButlerRegistry: + def makeRegistry(self, share_repo_with: _ButlerRegistry | None = None) -> _ButlerRegistry: if share_repo_with is None: _, filename = tempfile.mkstemp(dir=self.root, suffix=".sqlite3") else: @@ -242,7 +242,7 @@ class SqliteMemoryRegistryTests(RegistryTests): def getDataDir(cls) -> str: return os.path.normpath(os.path.join(os.path.dirname(__file__), "data", "registry")) - def makeRegistry(self, share_repo_with: ButlerRegistry | None = None) -> ButlerRegistry | None: + def makeRegistry(self, share_repo_with: _ButlerRegistry | None = None) -> _ButlerRegistry | None: if share_repo_with is not None: return None config = self.makeRegistryConfig()