Skip to content

Commit

Permalink
Try pydantic v1 API explicitly
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
timj committed Jul 3, 2023
1 parent 6934312 commit b349542
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 15 deletions.
6 changes: 5 additions & 1 deletion python/lsst/daf/butler/_quantum_backed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion python/lsst/daf/butler/core/datasets/ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion python/lsst/daf/butler/core/datasets/type.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion python/lsst/daf/butler/core/datastoreCacheManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion python/lsst/daf/butler/core/datastoreRecordData.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion python/lsst/daf/butler/core/dimensions/_coordinate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion python/lsst/daf/butler/core/dimensions/_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion python/lsst/daf/butler/core/dimensions/_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion python/lsst/daf/butler/core/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
6 changes: 5 additions & 1 deletion python/lsst/daf/butler/core/quantum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion python/lsst/daf/butler/core/serverModels.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion python/lsst/daf/butler/registry/obscore/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 5 additions & 1 deletion python/lsst/daf/butler/registry/wildcards.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion python/lsst/daf/butler/tests/_examplePythonTypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion python/lsst/daf/butler/tests/dict_convertible_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit b349542

Please sign in to comment.