-
Notifications
You must be signed in to change notification settings - Fork 179
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
chore: Migrate Python projects from Pydantic v1 to v2 #14871
Draft
ahiuchingau
wants to merge
75
commits into
edge
Choose a base branch
from
chore_update-pydantic-v2
base: edge
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 16 commits
Commits
Show all changes
75 commits
Select commit
Hold shift + click to select a range
c2d17fb
update pydantic & fix all mypy errors
ahiuchingau cae6028
hardware: update pydantic & fix all mypy errors
ahiuchingau 8779c87
hardware: fix Pipfile
ahiuchingau 19f7110
api: update pydantic & fix mypy errors
ahiuchingau b5c8eab
shared-data: add Vec3f
ahiuchingau ac77352
shared-data: rename labware_definition to models
ahiuchingau ef889d4
fix api mypy test errors
ahiuchingau b3ea918
update api
ahiuchingau ea9e17e
fix protocol_engine tests
ahiuchingau 90b7fab
fix(api): tests
ahiuchingau 16b69eb
update command schema 8.json
ahiuchingau 528a825
shared-data: deprecate json_encoder and use v2 serializer
ahiuchingau ff83a57
fix api tests
ahiuchingau 80a7000
api(src): update deprecated code
ahiuchingau 1291aa1
api: linter
ahiuchingau 27bbbec
shared-data: remove deprecated code
ahiuchingau b646339
shared-data: mypy.ini removed commented out override
ahiuchingau 7588a3f
robot-server & server-utils: update pipenv
ahiuchingau 0b391da
robot-server: add pydantic_settings
ahiuchingau 8114936
robot-server: bump-pydantic to v2
ahiuchingau 52b5899
robot-server: fix lint errors
ahiuchingau 9b02831
robot-server: fix one test
ahiuchingau 2728cca
make lint
ahiuchingau c47cb10
add model serializer
ahiuchingau 82d5a51
Merge remote-tracking branch 'origin/edge' into chore_update-pydantic-v2
SyntaxColoring 96b4591
Post-merge code fixups.
SyntaxColoring 68fa893
Re-lock performance-metrics.
SyntaxColoring 86623ea
Use == version spec for robot-server, like we had before.
SyntaxColoring eac19cb
Remove outdated comment.
SyntaxColoring 7e1da8d
Update g-code-testing Pipfile.
SyntaxColoring 8ed4c1e
Update system-server Pipfile.
SyntaxColoring 913019f
Move performance-metrics from api [dev-packages] to [packages].
SyntaxColoring 2938afb
Re-lock api.
SyntaxColoring 2b7d068
_TestCommand.result and ReloadLabware.result need to default to None.
SyntaxColoring ac00d02
Revert SyncClient model_validate() changes.
SyntaxColoring 10aa798
Remove now-unneeded type-ignores.
SyntaxColoring fef7108
Don't instantiate BaseModel directly.
SyntaxColoring a7a69d7
Merge branch 'chore_update-pydantic-v2' of github.com:Opentrons/opent…
SyntaxColoring 46b024b
Regenerate command schema.
SyntaxColoring 7d73026
Delete empty log.txt.
SyntaxColoring 14bc816
Update .json() calls in cli.analyze.
SyntaxColoring 8dbe3d8
Run bump-pydantic on api.
SyntaxColoring d975c0e
Give up on test_command_executor.py.
SyntaxColoring e677a7e
Pin fastapi with == like we had before.
SyntaxColoring 3771b91
Ensure all fastapi pins consistently use 0.100.0.
SyntaxColoring ec14dd7
Move robot-server's dependency on performance-metrics to [packages].
SyntaxColoring d3c6ce2
Install pydantic-settings in system-server.
SyntaxColoring 34cae8c
Add pydantic-settings to robot-server/setup.py.
SyntaxColoring 7ee2b47
Re-lock everything.
SyntaxColoring 1b3b099
robot-server: Run bump-pydantic.
SyntaxColoring 06e87fd
robot-server: Remove now-unneeded type-ignores.
SyntaxColoring 9cdeb04
robot-server: Add a unit test for robot_server.persistence.pydantic.
SyntaxColoring 5f60e97
robot-server: Post-merge fixups to robot_server.persistence.pydantic.
SyntaxColoring dd461e9
system-server: Run bump-pydantic.
SyntaxColoring 3b1da95
system-server: Manual fixups.
SyntaxColoring ff3db4e
Merge remote-tracking branch 'origin/edge' into chore_update-pydantic-v2
SyntaxColoring 14f5c10
g-code-testing: Run bump-pydantic [WIP]
SyntaxColoring 01f0ed9
WIP: Fix some slow stuff with TypeAdapter?
SyntaxColoring de2b400
robot-server: Update error messages in tests.
SyntaxColoring d674c66
Revert BaseModel -> BaseResponseBody changes.
SyntaxColoring 1d95e40
Merge branch 'edge' into chore_update-pydantic-v2
sfoster1 18a3b22
chore: format and fix lints
sfoster1 9417cd0
s-d: fix tests
sfoster1 315a370
api: fix testst
sfoster1 fea1fad
schema format
sfoster1 7fecd09
make this installable per https://github.com/pypa/setuptools/issues/4483
sfoster1 b0c849f
Merge branch 'edge' into chore_update-pydantic-v2
sfoster1 8082363
chore: pydantic 2.9.0
sfoster1 b3f7e04
chore: mypy 1.11.0
sfoster1 5a781f1
chore: py lint fixes
sfoster1 bab482b
chore: fix hardware-testing
sfoster1 aaf8f58
chore: fix api runtime type dependencies
sfoster1 9159f4a
fixup command schema
sfoster1 666b3ff
fixup some server tests
sfoster1 cdbf235
Merge branch 'edge' into chore_update-pydantic-v2
sfoster1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
from typing_extensions import Literal | ||
from opentrons.hardware_control.modules.types import ModuleType | ||
from opentrons.hardware_control.types import OT3Mount | ||
from pydantic import BaseModel, Field, validator | ||
from pydantic import field_validator, BaseModel, Field, PlainSerializer | ||
from datetime import datetime | ||
|
||
from opentrons_shared_data.pipette.dev_types import LabwareUri | ||
|
@@ -12,15 +12,21 @@ | |
from opentrons.calibration_storage import types | ||
|
||
|
||
DatetimeType = typing.Annotated[ | ||
datetime, | ||
PlainSerializer(lambda x: x.isoformat(), when_used="json"), | ||
] | ||
Comment on lines
+15
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto. |
||
|
||
|
||
class CalibrationStatus(BaseModel): | ||
markedBad: bool = False | ||
source: typing.Optional[types.SourceType] = None | ||
markedAt: typing.Optional[datetime] = None | ||
markedAt: typing.Optional[DatetimeType] = None | ||
|
||
|
||
class TipLengthModel(BaseModel): | ||
tipLength: float = Field(..., description="Tip length data found from calibration.") | ||
lastModified: datetime = Field( | ||
lastModified: DatetimeType = Field( | ||
..., description="The last time this tip length was calibrated." | ||
) | ||
uri: typing.Union[LabwareUri, Literal[""]] = Field( | ||
|
@@ -34,22 +40,19 @@ class TipLengthModel(BaseModel): | |
description="The status of the calibration data.", | ||
) | ||
|
||
@validator("tipLength") | ||
@field_validator("tipLength") | ||
@classmethod | ||
def ensure_tip_length_positive(cls, tipLength: float) -> float: | ||
if tipLength < 0.0: | ||
raise ValueError("Tip Length must be a positive number") | ||
return tipLength | ||
|
||
class Config: | ||
json_encoders = {datetime: lambda obj: obj.isoformat()} | ||
json_decoders = {datetime: lambda obj: datetime.fromisoformat(obj)} | ||
|
||
|
||
class BeltCalibrationModel(BaseModel): | ||
attitude: types.AttitudeMatrix = Field( | ||
..., description="Attitude matrix for belts found from calibration." | ||
) | ||
lastModified: datetime = Field( | ||
lastModified: DatetimeType = Field( | ||
..., description="The last time this deck was calibrated." | ||
) | ||
source: types.SourceType = Field( | ||
|
@@ -63,14 +66,10 @@ class BeltCalibrationModel(BaseModel): | |
description="The status of the calibration data.", | ||
) | ||
|
||
class Config: | ||
json_encoders = {datetime: lambda obj: obj.isoformat()} | ||
json_decoders = {datetime: lambda obj: datetime.fromisoformat(obj)} | ||
|
||
|
||
class InstrumentOffsetModel(BaseModel): | ||
offset: Point = Field(..., description="Instrument offset found from calibration.") | ||
lastModified: datetime = Field( | ||
lastModified: DatetimeType = Field( | ||
..., description="The last time this instrument was calibrated." | ||
) | ||
source: types.SourceType = Field( | ||
|
@@ -81,10 +80,6 @@ class InstrumentOffsetModel(BaseModel): | |
description="The status of the calibration data.", | ||
) | ||
|
||
class Config: | ||
json_encoders = {datetime: lambda obj: obj.isoformat()} | ||
json_decoders = {datetime: lambda obj: datetime.fromisoformat(obj)} | ||
|
||
|
||
class ModuleOffsetModel(BaseModel): | ||
offset: Point = Field(..., description="Module offset found from calibration.") | ||
|
@@ -99,7 +94,7 @@ class ModuleOffsetModel(BaseModel): | |
..., | ||
description="The unique id of the instrument used to calibrate this module.", | ||
) | ||
lastModified: datetime = Field( | ||
lastModified: DatetimeType = Field( | ||
..., description="The last time this module was calibrated." | ||
) | ||
source: types.SourceType = Field( | ||
|
@@ -109,7 +104,3 @@ class ModuleOffsetModel(BaseModel): | |
default_factory=CalibrationStatus, | ||
description="The status of the calibration data.", | ||
) | ||
|
||
class Config: | ||
json_encoders = {datetime: lambda obj: obj.isoformat()} | ||
json_decoders = {datetime: lambda obj: datetime.fromisoformat(obj)} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm inferring that this is replacing the old
json_encoders
config. Does something need to replace the oldjson_decoders
config, to match?