From 7214c4c1c569ce5bc06d246a19f561e7e44d1fce Mon Sep 17 00:00:00 2001 From: Tim Jenness Date: Mon, 3 Jul 2023 12:39:42 -0700 Subject: [PATCH 1/3] Force v1 pydantic API if running v2 --- python/lsst/pipe/base/_task_metadata.py | 6 +++++- python/lsst/pipe/base/graph/quantumNode.py | 6 +++++- python/lsst/pipe/base/tests/mocks/_storage_class.py | 5 ++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/python/lsst/pipe/base/_task_metadata.py b/python/lsst/pipe/base/_task_metadata.py index 67af6a4d..5abc97b2 100644 --- a/python/lsst/pipe/base/_task_metadata.py +++ b/python/lsst/pipe/base/_task_metadata.py @@ -27,7 +27,11 @@ from collections.abc import Collection, Iterator, Mapping, Sequence from typing import Any, Protocol -from pydantic import BaseModel, Field, StrictBool, StrictFloat, StrictInt, StrictStr +try: + from pydantic.v1 import BaseModel, Field, StrictBool, StrictFloat, StrictInt, StrictStr +except ModuleNotFoundError: + from pydantic import BaseModel, Field, StrictBool, StrictFloat, StrictInt, StrictStr + _DEPRECATION_REASON = "Will be removed after v25." _DEPRECATION_VERSION = "v24" diff --git a/python/lsst/pipe/base/graph/quantumNode.py b/python/lsst/pipe/base/graph/quantumNode.py index b5df5d01..6ddb3895 100644 --- a/python/lsst/pipe/base/graph/quantumNode.py +++ b/python/lsst/pipe/base/graph/quantumNode.py @@ -36,7 +36,11 @@ SerializedQuantum, ) from lsst.utils.introspection import find_outside_stacklevel -from pydantic import BaseModel + +try: + from pydantic.v1 import BaseModel +except ModuleNotFoundError: + from pydantic import BaseModel from ..pipeline import TaskDef diff --git a/python/lsst/pipe/base/tests/mocks/_storage_class.py b/python/lsst/pipe/base/tests/mocks/_storage_class.py index fdacfc62..1d70ebf6 100644 --- a/python/lsst/pipe/base/tests/mocks/_storage_class.py +++ b/python/lsst/pipe/base/tests/mocks/_storage_class.py @@ -34,7 +34,10 @@ from collections.abc import Callable, Iterable, Mapping from typing import Any, cast -import pydantic +try: + import pydantic.v1 as pydantic +except ModuleNotFoundError: + import pydantic from lsst.daf.butler import ( DatasetComponent, Formatter, From c992a7abb61af4313af8fd1311d8eb7b60f2f068 Mon Sep 17 00:00:00 2001 From: Tim Jenness Date: Tue, 4 Jul 2023 18:29:46 -0700 Subject: [PATCH 2/3] Allow pydantic <3 to be used --- pyproject.toml | 2 +- requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 29adada6..c88335da 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,7 +26,7 @@ dependencies = [ "lsst-daf-butler", "lsst-pex-config", "astropy", - "pydantic", + "pydantic <3.0", "networkx", "pyyaml >= 5.1", "numpy >= 1.17", diff --git a/requirements.txt b/requirements.txt index 79d5616f..1c1d5f11 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ pyyaml >= 5.1 -pydantic < 2 +pydantic < 3.0 numpy >= 1.17 networkx frozendict From 4953f65a3491e4915521baf16d078a3e3b59c428 Mon Sep 17 00:00:00 2001 From: Tim Jenness Date: Wed, 5 Jul 2023 07:45:21 -0700 Subject: [PATCH 3/3] Ignore second pydantic import in mypy --- python/lsst/pipe/base/_task_metadata.py | 2 +- python/lsst/pipe/base/graph/quantumNode.py | 2 +- python/lsst/pipe/base/tests/mocks/_storage_class.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/python/lsst/pipe/base/_task_metadata.py b/python/lsst/pipe/base/_task_metadata.py index 5abc97b2..5ec6caca 100644 --- a/python/lsst/pipe/base/_task_metadata.py +++ b/python/lsst/pipe/base/_task_metadata.py @@ -30,7 +30,7 @@ try: from pydantic.v1 import BaseModel, Field, StrictBool, StrictFloat, StrictInt, StrictStr except ModuleNotFoundError: - from pydantic import BaseModel, Field, StrictBool, StrictFloat, StrictInt, StrictStr + from pydantic import BaseModel, Field, StrictBool, StrictFloat, StrictInt, StrictStr # type: ignore _DEPRECATION_REASON = "Will be removed after v25." diff --git a/python/lsst/pipe/base/graph/quantumNode.py b/python/lsst/pipe/base/graph/quantumNode.py index 6ddb3895..14767ae2 100644 --- a/python/lsst/pipe/base/graph/quantumNode.py +++ b/python/lsst/pipe/base/graph/quantumNode.py @@ -40,7 +40,7 @@ try: from pydantic.v1 import BaseModel except ModuleNotFoundError: - from pydantic import BaseModel + from pydantic import BaseModel # type: ignore from ..pipeline import TaskDef diff --git a/python/lsst/pipe/base/tests/mocks/_storage_class.py b/python/lsst/pipe/base/tests/mocks/_storage_class.py index 1d70ebf6..379800c2 100644 --- a/python/lsst/pipe/base/tests/mocks/_storage_class.py +++ b/python/lsst/pipe/base/tests/mocks/_storage_class.py @@ -37,7 +37,7 @@ try: import pydantic.v1 as pydantic except ModuleNotFoundError: - import pydantic + import pydantic # type: ignore from lsst.daf.butler import ( DatasetComponent, Formatter,