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-39876: Add bandaid for pydantic v2 #859

Merged
merged 6 commits into from
Jul 5, 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
2 changes: 1 addition & 1 deletion doc/lsst.daf.butler/configuring.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The main sections of the YAML file are handled separately by each sub configurat
Each config specialization, registry, schema, storage class, composites, and dimensions knows the name of the key for its own section of the configuration and knows the names of files providing overrides and defaults for the configuration.
Additionally, if the sub configuration contains a ``cls`` key, that class is imported and an additional configuration file name can be provided by asking the class for its defaultConfigFile property.
All the keys within a sub configuration are processed by the class constructed from ``cls``.
The primary source of default values comes from the ``configs`` resource (accessed using `pkg_resources` and package ``lsst.daf.butler``) –- this directory contains YAML files matching the names specified in the sub config classes and also can include names specified by the corresponding component class (for example `~lsst.daf.butler.datastores.fileDatastore.FileDatastore` specifies that configuration should be found in ``datastores/fileDatastore.yaml``.
The primary source of default values comes from the ``configs`` resource (accessed using `importlib.resources` and package ``lsst.daf.butler``) –- this directory contains YAML files matching the names specified in the sub config classes and also can include names specified by the corresponding component class (for example `~lsst.daf.butler.datastores.fileDatastore.FileDatastore` specifies that configuration should be found in ``datastores/fileDatastore.yaml``.
There are additional search paths that can be included when a config object is constructed:

1. Explicit list of directory paths to search passed into the constructor.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dependencies = [
"lsst-resources",
"lsst-daf-relation",
"deprecated >= 1.2",
"pydantic",
"pydantic <3.0",
]

dynamic = ["version"]
Expand Down
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 # type: ignore

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 @@ -36,7 +36,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 # type: ignore

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 # type: ignore

from ..configSupport import LookupKey
from ..dimensions import DimensionGraph, SerializedDimensionGraph
Expand Down
8 changes: 6 additions & 2 deletions 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 # type: ignore

from .config import ConfigSubset
from .configSupport import processLookupConfigs
Expand Down Expand Up @@ -135,7 +139,7 @@ class CacheEntry(BaseModel):
ref: DatasetId
"""ID of this dataset."""

component: str | None
component: str | None = None
"""Component for this disassembled composite (optional)."""

@classmethod
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 # type: ignore

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 # type: ignore

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 # type: ignore

from .._topology import TopologicalFamily, TopologicalSpace
from ..json import from_json_pydantic, to_json_pydantic
Expand Down
14 changes: 13 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,19 @@

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 ( # type: ignore
BaseModel,
Field,
StrictBool,
StrictFloat,
StrictInt,
StrictStr,
create_model,
)

from ..json import from_json_pydantic, to_json_pydantic
from ..persistenceContext import PersistenceContextVars
Expand Down
10 changes: 7 additions & 3 deletions 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 # type: ignore

_LONG_LOG_FORMAT = "{levelname} {asctime} {name} {filename}:{lineno} - {message}"
"""Default format for log records."""
Expand Down Expand Up @@ -175,10 +179,10 @@ class ButlerLogRecord(BaseModel):
filename: str
pathname: str
lineno: int
funcName: str | None
funcName: str | None = None
process: int
processName: str
exc_info: str | None
exc_info: str | None = None
MDC: dict[str, str]
Comment on lines -178 to 186
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work with v1? I thought that pydantic (v1) does not allow non-default attributes after default ones (but I may be thinking of dataclasses)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made that change first with the auto updater and it seemed to be okay. I am running Jenkins over night on everything so I'll see whether everything works in the morning.


class Config:
Expand Down
10 changes: 7 additions & 3 deletions python/lsst/daf/butler/core/quantum.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@

from lsst.utils import doImportType
from lsst.utils.introspection import find_outside_stacklevel
from pydantic import BaseModel

try:
from pydantic.v1 import BaseModel
except ModuleNotFoundError:
from pydantic import BaseModel # type: ignore

from .datasets import DatasetRef, DatasetType, SerializedDatasetRef, SerializedDatasetType
from .datastoreRecordData import DatastoreRecordData, SerializedDatastoreRecordData
Expand Down Expand Up @@ -72,8 +76,8 @@ def _reconstructDatasetRef(
class SerializedQuantum(BaseModel):
"""Simplified model of a `Quantum` suitable for serialization."""

taskName: str | None
dataId: SerializedDataCoordinate | None
taskName: str | None = None
dataId: SerializedDataCoordinate | None = None
datasetTypeMapping: Mapping[str, SerializedDatasetType]
initInputs: Mapping[str, tuple[SerializedDatasetRef, list[int]]]
inputs: Mapping[str, list[tuple[SerializedDatasetRef, list[int]]]]
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 # type: ignore

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 # type: ignore


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 # type: ignore

from ..core import DatasetType
from ..core.utils import globToRegex
Expand Down
12 changes: 8 additions & 4 deletions 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 # type: ignore

if TYPE_CHECKING:
from lsst.daf.butler import Butler, Datastore, FormatterFactory
Expand Down Expand Up @@ -266,9 +270,9 @@ def makeFromDict(cls, exportDict: dict[str, list | dict | None]) -> MetricsExamp
class MetricsExampleModel(BaseModel):
"""A variant of `MetricsExample` based on model."""

summary: dict[str, Any] | None
output: dict[str, Any] | None
data: list[Any] | None
summary: dict[str, Any] | None = None
output: dict[str, Any] | None = None
data: list[Any] | None = None

@classmethod
def from_metrics(cls, metrics: MetricsExample) -> MetricsExampleModel:
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 # type: ignore


class DictConvertibleModel(BaseModel):
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pyyaml >= 5.1
astropy >= 4.0
click >7.0
sqlalchemy >= 1.4
pydantic
pydantic <3.0
httpx
deprecated >=1.2
git+https://github.com/lsst/sphgeom@main#egg=lsst-sphgeom
Expand Down
1 change: 0 additions & 1 deletion types.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
types-requests
types-PyYAML
types-pkg_resources
types-Deprecated
Loading