From b3495428ca8d12e7e086f5e77f832cbd72b6fdc6 Mon Sep 17 00:00:00 2001 From: Tim Jenness Date: Mon, 3 Jul 2023 12:33:01 -0700 Subject: [PATCH] Try pydantic v1 API explicitly pydantic v2 is not compatible with daf_butler at the moment. Change all the imports to first try to load the v1 API explicitly before falling back to the default API. pydantic.v1 works with v2. --- python/lsst/daf/butler/_quantum_backed.py | 6 +++++- python/lsst/daf/butler/core/datasets/ref.py | 6 +++++- python/lsst/daf/butler/core/datasets/type.py | 5 ++++- python/lsst/daf/butler/core/datastoreCacheManager.py | 6 +++++- python/lsst/daf/butler/core/datastoreRecordData.py | 6 +++++- python/lsst/daf/butler/core/dimensions/_coordinate.py | 6 +++++- python/lsst/daf/butler/core/dimensions/_graph.py | 6 +++++- python/lsst/daf/butler/core/dimensions/_records.py | 6 +++++- python/lsst/daf/butler/core/logging.py | 6 +++++- python/lsst/daf/butler/core/quantum.py | 6 +++++- python/lsst/daf/butler/core/serverModels.py | 6 +++++- python/lsst/daf/butler/registry/obscore/_config.py | 5 ++++- python/lsst/daf/butler/registry/wildcards.py | 6 +++++- python/lsst/daf/butler/tests/_examplePythonTypes.py | 6 +++++- python/lsst/daf/butler/tests/dict_convertible_model.py | 5 ++++- 15 files changed, 72 insertions(+), 15 deletions(-) diff --git a/python/lsst/daf/butler/_quantum_backed.py b/python/lsst/daf/butler/_quantum_backed.py index 9f44492758..1111da44f2 100644 --- a/python/lsst/daf/butler/_quantum_backed.py +++ b/python/lsst/daf/butler/_quantum_backed.py @@ -32,7 +32,11 @@ from deprecated.sphinx import deprecated from lsst.resources import ResourcePathExpression -from pydantic import BaseModel + +try: + from pydantic.v1 import BaseModel +except ModuleNotFoundError: + from pydantic import BaseModel from ._butlerConfig import ButlerConfig from ._deferredDatasetHandle import DeferredDatasetHandle diff --git a/python/lsst/daf/butler/core/datasets/ref.py b/python/lsst/daf/butler/core/datasets/ref.py index 005fd5b1ff..9d5db98d80 100644 --- a/python/lsst/daf/butler/core/datasets/ref.py +++ b/python/lsst/daf/butler/core/datasets/ref.py @@ -35,7 +35,11 @@ from typing import TYPE_CHECKING, Any, ClassVar from lsst.utils.classes import immutable -from pydantic import BaseModel, StrictStr, validator + +try: + from pydantic.v1 import BaseModel, StrictStr, validator +except ModuleNotFoundError: + from pydantic import BaseModel, StrictStr, validator from ..configSupport import LookupKey from ..dimensions import DataCoordinate, DimensionGraph, DimensionUniverse, SerializedDataCoordinate diff --git a/python/lsst/daf/butler/core/datasets/type.py b/python/lsst/daf/butler/core/datasets/type.py index 1ddbc018c0..f4da5d16c7 100644 --- a/python/lsst/daf/butler/core/datasets/type.py +++ b/python/lsst/daf/butler/core/datasets/type.py @@ -29,7 +29,10 @@ from types import MappingProxyType from typing import TYPE_CHECKING, Any, ClassVar -from pydantic import BaseModel, StrictBool, StrictStr +try: + from pydantic.v1 import BaseModel, StrictBool, StrictStr +except ModuleNotFoundError: + from pydantic import BaseModel, StrictBool, StrictStr from ..configSupport import LookupKey from ..dimensions import DimensionGraph, SerializedDimensionGraph diff --git a/python/lsst/daf/butler/core/datastoreCacheManager.py b/python/lsst/daf/butler/core/datastoreCacheManager.py index 1a679945ee..f39c9323c0 100644 --- a/python/lsst/daf/butler/core/datastoreCacheManager.py +++ b/python/lsst/daf/butler/core/datastoreCacheManager.py @@ -46,7 +46,11 @@ from typing import TYPE_CHECKING from lsst.resources import ResourcePath -from pydantic import BaseModel, PrivateAttr + +try: + from pydantic.v1 import BaseModel, PrivateAttr +except ModuleNotFoundError: + from pydantic import BaseModel, PrivateAttr from .config import ConfigSubset from .configSupport import processLookupConfigs diff --git a/python/lsst/daf/butler/core/datastoreRecordData.py b/python/lsst/daf/butler/core/datastoreRecordData.py index c6d9f31e0b..5081b4a7b2 100644 --- a/python/lsst/daf/butler/core/datastoreRecordData.py +++ b/python/lsst/daf/butler/core/datastoreRecordData.py @@ -32,7 +32,11 @@ from lsst.utils import doImportType from lsst.utils.introspection import get_full_type_name -from pydantic import BaseModel + +try: + from pydantic.v1 import BaseModel +except ModuleNotFoundError: + from pydantic import BaseModel from .datasets import DatasetId from .dimensions import DimensionUniverse diff --git a/python/lsst/daf/butler/core/dimensions/_coordinate.py b/python/lsst/daf/butler/core/dimensions/_coordinate.py index 2c104b1d46..4172bbd2ec 100644 --- a/python/lsst/daf/butler/core/dimensions/_coordinate.py +++ b/python/lsst/daf/butler/core/dimensions/_coordinate.py @@ -35,7 +35,11 @@ from deprecated.sphinx import deprecated from lsst.sphgeom import IntersectionRegion, Region -from pydantic import BaseModel + +try: + from pydantic.v1 import BaseModel +except ModuleNotFoundError: + from pydantic import BaseModel from ..json import from_json_pydantic, to_json_pydantic from ..named import NamedKeyDict, NamedKeyMapping, NamedValueAbstractSet, NameLookupMapping diff --git a/python/lsst/daf/butler/core/dimensions/_graph.py b/python/lsst/daf/butler/core/dimensions/_graph.py index 23f9948223..ea013aa23a 100644 --- a/python/lsst/daf/butler/core/dimensions/_graph.py +++ b/python/lsst/daf/butler/core/dimensions/_graph.py @@ -29,7 +29,11 @@ from typing import TYPE_CHECKING, Any, ClassVar from lsst.utils.classes import cached_getter, immutable -from pydantic import BaseModel + +try: + from pydantic.v1 import BaseModel +except ModuleNotFoundError: + from pydantic import BaseModel from .._topology import TopologicalFamily, TopologicalSpace from ..json import from_json_pydantic, to_json_pydantic diff --git a/python/lsst/daf/butler/core/dimensions/_records.py b/python/lsst/daf/butler/core/dimensions/_records.py index 95f7f12bd8..d57f63f5a3 100644 --- a/python/lsst/daf/butler/core/dimensions/_records.py +++ b/python/lsst/daf/butler/core/dimensions/_records.py @@ -27,7 +27,11 @@ import lsst.sphgeom from lsst.utils.classes import immutable -from pydantic import BaseModel, Field, StrictBool, StrictFloat, StrictInt, StrictStr, create_model + +try: + from pydantic.v1 import BaseModel, Field, StrictBool, StrictFloat, StrictInt, StrictStr, create_model +except ModuleNotFoundError: + from pydantic import BaseModel, Field, StrictBool, StrictFloat, StrictInt, StrictStr, create_model from ..json import from_json_pydantic, to_json_pydantic from ..timespan import Timespan, TimespanDatabaseRepresentation diff --git a/python/lsst/daf/butler/core/logging.py b/python/lsst/daf/butler/core/logging.py index 2a752acc5f..6b1d5ee1b4 100644 --- a/python/lsst/daf/butler/core/logging.py +++ b/python/lsst/daf/butler/core/logging.py @@ -31,7 +31,11 @@ from lsst.utils.introspection import get_full_type_name from lsst.utils.iteration import isplit -from pydantic import BaseModel, PrivateAttr + +try: + from pydantic.v1 import BaseModel, PrivateAttr +except ModuleNotFoundError: + from pydantic import BaseModel, PrivateAttr _LONG_LOG_FORMAT = "{levelname} {asctime} {name} {filename}:{lineno} - {message}" """Default format for log records.""" diff --git a/python/lsst/daf/butler/core/quantum.py b/python/lsst/daf/butler/core/quantum.py index c93663142c..bf96fce6eb 100644 --- a/python/lsst/daf/butler/core/quantum.py +++ b/python/lsst/daf/butler/core/quantum.py @@ -27,7 +27,11 @@ from typing import Any from lsst.utils import doImportType -from pydantic import BaseModel + +try: + from pydantic.v1 import BaseModel +except ModuleNotFoundError: + from pydantic import BaseModel from .datasets import DatasetRef, DatasetType, SerializedDatasetRef, SerializedDatasetType from .datastoreRecordData import DatastoreRecordData, SerializedDatastoreRecordData diff --git a/python/lsst/daf/butler/core/serverModels.py b/python/lsst/daf/butler/core/serverModels.py index d89d50b341..f9609f213c 100644 --- a/python/lsst/daf/butler/core/serverModels.py +++ b/python/lsst/daf/butler/core/serverModels.py @@ -34,7 +34,11 @@ from typing import Any, ClassVar from lsst.utils.iteration import ensure_iterable -from pydantic import BaseModel, Field, validator + +try: + from pydantic.v1 import BaseModel, Field, validator +except ModuleNotFoundError: + from pydantic import BaseModel, Field, validator from .dimensions import DataIdValue, SerializedDataCoordinate from .utils import globToRegex diff --git a/python/lsst/daf/butler/registry/obscore/_config.py b/python/lsst/daf/butler/registry/obscore/_config.py index 79c115baf9..94d6643031 100644 --- a/python/lsst/daf/butler/registry/obscore/_config.py +++ b/python/lsst/daf/butler/registry/obscore/_config.py @@ -35,7 +35,10 @@ from collections.abc import Mapping from typing import Any -from pydantic import BaseModel, StrictBool, StrictFloat, StrictInt, StrictStr, validator +try: + from pydantic.v1 import BaseModel, StrictBool, StrictFloat, StrictInt, StrictStr, validator +except ModuleNotFoundError: + from pydantic import BaseModel, StrictBool, StrictFloat, StrictInt, StrictStr, validator class ExtraColumnType(str, enum.Enum): diff --git a/python/lsst/daf/butler/registry/wildcards.py b/python/lsst/daf/butler/registry/wildcards.py index 7622f84184..6748f4d5ce 100644 --- a/python/lsst/daf/butler/registry/wildcards.py +++ b/python/lsst/daf/butler/registry/wildcards.py @@ -35,7 +35,11 @@ from deprecated.sphinx import deprecated from lsst.utils.iteration import ensure_iterable -from pydantic import BaseModel + +try: + from pydantic.v1 import BaseModel +except ModuleNotFoundError: + from pydantic import BaseModel from ..core import DatasetType from ..core.utils import globToRegex diff --git a/python/lsst/daf/butler/tests/_examplePythonTypes.py b/python/lsst/daf/butler/tests/_examplePythonTypes.py index 3e8b61a678..31133f2e63 100644 --- a/python/lsst/daf/butler/tests/_examplePythonTypes.py +++ b/python/lsst/daf/butler/tests/_examplePythonTypes.py @@ -43,7 +43,11 @@ from typing import TYPE_CHECKING, Any from lsst.daf.butler import StorageClass, StorageClassDelegate -from pydantic import BaseModel + +try: + from pydantic.v1 import BaseModel +except ModuleNotFoundError: + from pydantic import BaseModel if TYPE_CHECKING: from lsst.daf.butler import Butler, Datastore, FormatterFactory diff --git a/python/lsst/daf/butler/tests/dict_convertible_model.py b/python/lsst/daf/butler/tests/dict_convertible_model.py index 2969cedc63..05aa0051ce 100644 --- a/python/lsst/daf/butler/tests/dict_convertible_model.py +++ b/python/lsst/daf/butler/tests/dict_convertible_model.py @@ -25,7 +25,10 @@ from collections.abc import Mapping -from pydantic import BaseModel, Field +try: + from pydantic.v1 import BaseModel, Field +except ModuleNotFoundError: + from pydantic import BaseModel, Field class DictConvertibleModel(BaseModel):