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-42302: drop support for Pydantic v1 #280

Merged
merged 3 commits into from
Jan 4, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build_docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.11'
python-version: "3.11"
cache: "pip"
cache-dependency-path: "setup.cfg"

Expand All @@ -35,7 +35,7 @@ jobs:
run: pip install --no-deps -v .

- name: Install documenteer
run: pip install 'documenteer[pipelines]>=0.8'
run: pip install 'documenteer[pipelines]==0.8.2'

- name: Build documentation
working-directory: ./doc
Expand Down
1 change: 1 addition & 0 deletions doc/changes/DM-42302.misc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Drop support for Pydantic 1.x.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies = [
"lsst-pipe-base",
"click",
"astropy",
"pydantic <3.0",
"pydantic >=2,<3.0",
"networkx",
"psutil"
]
Expand Down
32 changes: 11 additions & 21 deletions python/lsst/ctrl/mpexec/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@

import pydantic
from lsst.daf.butler import DataCoordinate, DataId, DataIdValue
from lsst.daf.butler._compat import PYDANTIC_V2, _BaseModelCompat
from lsst.utils.introspection import get_full_type_name


Expand All @@ -61,7 +60,7 @@ class ExecutionStatus(enum.Enum):
SKIPPED = "skipped"


class ExceptionInfo(_BaseModelCompat):
class ExceptionInfo(pydantic.BaseModel):
"""Information about exception."""

className: str
Expand Down Expand Up @@ -89,7 +88,7 @@ def from_exception(cls, exception: Exception) -> ExceptionInfo:
return cls(className=get_full_type_name(exception), message=str(exception))


class QuantumReport(_BaseModelCompat):
class QuantumReport(pydantic.BaseModel):
"""Task execution report for a single Quantum.

Parameters
Expand Down Expand Up @@ -193,7 +192,7 @@ def from_exit_code(
)


class Report(_BaseModelCompat):
class Report(pydantic.BaseModel):
"""Execution report for the whole job with one or few quanta."""

status: ExecutionStatus = ExecutionStatus.SUCCESS
Expand All @@ -213,23 +212,14 @@ class Report(_BaseModelCompat):
quanta may not produce a report.
"""

if PYDANTIC_V2:
# Always want to validate the default value for cmdLine so
# use a model_validator.
@pydantic.model_validator(mode="before") # type: ignore[attr-defined]
@classmethod
def _set_cmdLine(cls, data: Any) -> Any:
if data.get("cmdLine") is None:
data["cmdLine"] = sys.argv
return data

else:

@pydantic.validator("cmdLine", always=True)
def _set_cmdLine(cls, v: list[str] | None) -> list[str]: # noqa: N805
if v is None:
v = sys.argv
return v
# Always want to validate the default value for cmdLine so
# use a model_validator.
@pydantic.model_validator(mode="before")
@classmethod
def _set_cmdLine(cls, data: Any) -> Any:
if data.get("cmdLine") is None:
data["cmdLine"] = sys.argv
return data

def set_exception(self, exception: Exception) -> None:
"""Update exception information from an exception object.
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
click
astropy
psutil
pydantic < 3.0
pydantic >=2,<3.0
networkx
git+https://github.com/lsst/resources@main#egg=lsst-resources
git+https://github.com/lsst/daf_butler@main#egg=lsst-daf-butler
Expand Down