Skip to content

Commit

Permalink
robot-server: fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ahiuchingau committed Apr 12, 2024
1 parent 8114936 commit 52b5899
Show file tree
Hide file tree
Showing 52 changed files with 646 additions and 595 deletions.
6 changes: 3 additions & 3 deletions robot-server/robot_server/commands/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ async def create_command(
response_data = cast(StatelessCommand, engine.state_view.commands.get(command.id))

return await PydanticResponse.create(
content=SimpleBody.construct(data=response_data),
content=SimpleBody.model_construct(data=response_data),
status_code=status.HTTP_201_CREATED,
)

Expand Down Expand Up @@ -160,7 +160,7 @@ async def get_commands_list(
meta = MultiBodyMeta(cursor=cmd_slice.cursor, totalLength=cmd_slice.total_length)

return await PydanticResponse.create(
content=SimpleMultiBody.construct(data=commands, meta=meta),
content=SimpleMultiBody.model_construct(data=commands, meta=meta),
status_code=status.HTTP_200_OK,
)

Expand Down Expand Up @@ -196,6 +196,6 @@ async def get_command(
raise CommandNotFound.from_exc(e).as_error(status.HTTP_404_NOT_FOUND) from e

return await PydanticResponse.create(
content=SimpleBody.construct(data=cast(StatelessCommand, command)),
content=SimpleBody.model_construct(data=cast(StatelessCommand, command)),
status_code=status.HTTP_200_OK,
)
52 changes: 26 additions & 26 deletions robot-server/robot_server/deck_configuration/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,84 +4,84 @@
from . import models


_for_flex = models.DeckConfigurationRequest.construct(
_for_flex = models.DeckConfigurationRequest.model_construct(
cutoutFixtures=[
models.CutoutFixture.construct(
models.CutoutFixture.model_construct(
cutoutId="cutoutA1", cutoutFixtureId="singleLeftSlot"
),
models.CutoutFixture.construct(
models.CutoutFixture.model_construct(
cutoutId="cutoutB1", cutoutFixtureId="singleLeftSlot"
),
models.CutoutFixture.construct(
models.CutoutFixture.model_construct(
cutoutId="cutoutC1", cutoutFixtureId="singleLeftSlot"
),
models.CutoutFixture.construct(
models.CutoutFixture.model_construct(
cutoutId="cutoutD1", cutoutFixtureId="singleLeftSlot"
),
models.CutoutFixture.construct(
models.CutoutFixture.model_construct(
cutoutId="cutoutA2", cutoutFixtureId="singleCenterSlot"
),
models.CutoutFixture.construct(
models.CutoutFixture.model_construct(
cutoutId="cutoutB2", cutoutFixtureId="singleCenterSlot"
),
models.CutoutFixture.construct(
models.CutoutFixture.model_construct(
cutoutId="cutoutC2", cutoutFixtureId="singleCenterSlot"
),
models.CutoutFixture.construct(
models.CutoutFixture.model_construct(
cutoutId="cutoutD2", cutoutFixtureId="singleCenterSlot"
),
models.CutoutFixture.construct(
models.CutoutFixture.model_construct(
cutoutId="cutoutA3", cutoutFixtureId="trashBinAdapter"
),
models.CutoutFixture.construct(
models.CutoutFixture.model_construct(
cutoutId="cutoutB3", cutoutFixtureId="singleRightSlot"
),
models.CutoutFixture.construct(
models.CutoutFixture.model_construct(
cutoutId="cutoutC3", cutoutFixtureId="singleRightSlot"
),
models.CutoutFixture.construct(
models.CutoutFixture.model_construct(
cutoutId="cutoutD3", cutoutFixtureId="singleRightSlot"
),
]
)


_for_ot2 = models.DeckConfigurationRequest.construct(
_for_ot2 = models.DeckConfigurationRequest.model_construct(
cutoutFixtures=[
models.CutoutFixture.construct(
models.CutoutFixture.model_construct(
cutoutId="cutout1", cutoutFixtureId="singleStandardSlot"
),
models.CutoutFixture.construct(
models.CutoutFixture.model_construct(
cutoutId="cutout2", cutoutFixtureId="singleStandardSlot"
),
models.CutoutFixture.construct(
models.CutoutFixture.model_construct(
cutoutId="cutout3", cutoutFixtureId="singleStandardSlot"
),
models.CutoutFixture.construct(
models.CutoutFixture.model_construct(
cutoutId="cutout4", cutoutFixtureId="singleStandardSlot"
),
models.CutoutFixture.construct(
models.CutoutFixture.model_construct(
cutoutId="cutout5", cutoutFixtureId="singleStandardSlot"
),
models.CutoutFixture.construct(
models.CutoutFixture.model_construct(
cutoutId="cutout6", cutoutFixtureId="singleStandardSlot"
),
models.CutoutFixture.construct(
models.CutoutFixture.model_construct(
cutoutId="cutout7", cutoutFixtureId="singleStandardSlot"
),
models.CutoutFixture.construct(
models.CutoutFixture.model_construct(
cutoutId="cutout8", cutoutFixtureId="singleStandardSlot"
),
models.CutoutFixture.construct(
models.CutoutFixture.model_construct(
cutoutId="cutout9", cutoutFixtureId="singleStandardSlot"
),
models.CutoutFixture.construct(
models.CutoutFixture.model_construct(
cutoutId="cutout10", cutoutFixtureId="singleStandardSlot"
),
models.CutoutFixture.construct(
models.CutoutFixture.model_construct(
cutoutId="cutout11", cutoutFixtureId="singleStandardSlot"
),
models.CutoutFixture.construct(
models.CutoutFixture.model_construct(
cutoutId="cutout12", cutoutFixtureId="fixedTrashSlot"
),
]
Expand Down
6 changes: 3 additions & 3 deletions robot-server/robot_server/deck_configuration/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ async def put_deck_configuration( # noqa: D103
if len(validation_errors) == 0:
success_data = await store.set(request=request_body.data, last_modified_at=now)
return await PydanticResponse.create(
content=SimpleBody.construct(data=success_data)
content=SimpleBody.model_construct(data=success_data)
)
else:
error_data = validation_mapping.map_out(validation_errors)
return await PydanticResponse.create(
content=ErrorBody.construct(errors=error_data),
content=ErrorBody.model_construct(errors=error_data),
status_code=HTTP_422_UNPROCESSABLE_ENTITY,
)

Expand All @@ -107,5 +107,5 @@ async def get_deck_configuration( # noqa: D103
store: DeckConfigurationStore = fastapi.Depends(get_deck_configuration_store),
) -> PydanticResponse[SimpleBody[models.DeckConfigurationResponse]]:
return await PydanticResponse.create(
content=SimpleBody.construct(data=await store.get())
content=SimpleBody.model_construct(data=await store.get())
)
6 changes: 3 additions & 3 deletions robot-server/robot_server/deck_configuration/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ async def _get_assuming_locked(self) -> models.DeckConfigurationResponse:
# 5XX errors. We think falling back to an arbitrary default is safe because users
# of the Opentrons App will always have an opportunity to view and confirm their robot's
# deck configuration before running a protocol.
return models.DeckConfigurationResponse.construct(
return models.DeckConfigurationResponse.model_construct(
cutoutFixtures=defaults.for_deck_definition(
self._deck_type.value
).cutoutFixtures,
Expand All @@ -99,13 +99,13 @@ async def _get_assuming_locked(self) -> models.DeckConfigurationResponse:
else:
cutout_fixtures_from_storage, last_modified_at = from_storage
cutout_fixtures = [
models.CutoutFixture.construct(
models.CutoutFixture.model_construct(
cutoutFixtureId=e.cutout_fixture_id,
cutoutId=e.cutout_id,
)
for e in cutout_fixtures_from_storage
]
return models.DeckConfigurationResponse.construct(
return models.DeckConfigurationResponse.model_construct(
cutoutFixtures=cutout_fixtures,
lastModifiedAt=last_modified_at,
)
Expand Down
16 changes: 8 additions & 8 deletions robot-server/robot_server/instruments/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def _pipette_dict_to_pipette_res(
"""Convert PipetteDict to Pipette response model."""
if pipette_dict:
calibration_data = pipette_offset
return Pipette.construct(
return Pipette.model_construct(
firmwareVersion=str(fw_version) if fw_version else None,
ok=True,
mount=MountType.from_hw_mount(mount).value,
Expand All @@ -75,7 +75,7 @@ def _pipette_dict_to_pipette_res(
channels=pipette_dict["channels"],
min_volume=pipette_dict["min_volume"],
max_volume=pipette_dict["max_volume"],
calibratedOffset=InstrumentCalibrationData.construct(
calibratedOffset=InstrumentCalibrationData.model_construct(
offset=Vec3f(
x=calibration_data.offset.x,
y=calibration_data.offset.y,
Expand All @@ -84,9 +84,9 @@ def _pipette_dict_to_pipette_res(
source=calibration_data.source,
last_modified=calibration_data.last_modified,
reasonability_check_failures=[
InconsistentCalibrationFailure.construct(
InconsistentCalibrationFailure.model_construct(
offsets={
k.name: Vec3f.construct(x=v.x, y=v.y, z=v.z)
k.name: Vec3f.model_construct(x=v.x, y=v.y, z=v.z)
for k, v in failure.offsets.items()
},
limit=failure.limit,
Expand All @@ -106,7 +106,7 @@ def _gripper_dict_to_gripper_res(
) -> Gripper:
"""Convert GripperDict to Gripper response model."""
calibration_data = gripper_dict["calibration_offset"]
return Gripper.construct(
return Gripper.model_construct(
firmwareVersion=str(fw_version) if fw_version else None,
ok=True,
mount=MountType.EXTENSION.value,
Expand All @@ -115,7 +115,7 @@ def _gripper_dict_to_gripper_res(
subsystem=SubSystem.from_hw(HWSubSystem.of_mount(OT3Mount.GRIPPER)),
data=GripperData(
jawState=gripper_dict["state"].name.lower(),
calibratedOffset=InstrumentCalibrationData.construct(
calibratedOffset=InstrumentCalibrationData.model_construct(
offset=Vec3f(
x=calibration_data.offset.x,
y=calibration_data.offset.y,
Expand Down Expand Up @@ -219,7 +219,7 @@ async def _get_attached_instruments_ot3(
await hardware.cache_instruments(skip_if_would_block=True)
response_data = await _get_instrument_data(hardware)
return await PydanticResponse.create(
content=SimpleMultiBody.construct(
content=SimpleMultiBody.model_construct(
data=response_data,
meta=MultiBodyMeta(cursor=0, totalLength=len(response_data)),
),
Expand All @@ -243,7 +243,7 @@ async def _get_attached_instruments_ot2(
if pipette_dict
]
return await PydanticResponse.create(
content=SimpleMultiBody.construct(
content=SimpleMultiBody.model_construct(
data=response_data,
meta=MultiBodyMeta(cursor=0, totalLength=len(response_data)),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def _build_run(
created_at: datetime,
state_summary: Optional[StateSummary],
) -> MaintenanceRun:
state_summary = state_summary or StateSummary.construct(
state_summary = state_summary or StateSummary.model_construct(
status=EngineStatus.IDLE,
errors=[],
labware=[],
Expand All @@ -33,7 +33,7 @@ def _build_run(
modules=[],
liquids=[],
)
return MaintenanceRun.construct(
return MaintenanceRun.model_construct(
id=run_id,
createdAt=created_at,
status=state_summary.status,
Expand Down
10 changes: 5 additions & 5 deletions robot-server/robot_server/maintenance_runs/router/base_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ async def create_run(

log.info(f'Created an empty run "{run_id}"".')
return await PydanticResponse.create(
content=SimpleBody.construct(data=run_data),
content=SimpleBody.model_construct(data=run_data),
status_code=status.HTTP_201_CREATED,
)

Expand Down Expand Up @@ -221,11 +221,11 @@ async def get_current_run(

data = run_data_manager.get(current_run_id)
links = AllRunsLinks(
current=ResourceLink.construct(href=f"/maintenance_runs/{current_run_id}")
current=ResourceLink.model_construct(href=f"/maintenance_runs/{current_run_id}")
)

return await PydanticResponse.create(
content=Body.construct(data=data, links=links),
content=Body.model_construct(data=data, links=links),
status_code=status.HTTP_200_OK,
)

Expand All @@ -249,7 +249,7 @@ async def get_run(
run_data: Data of the run specified in the runId url parameter.
"""
return await PydanticResponse.create(
content=SimpleBody.construct(data=run_data),
content=SimpleBody.model_construct(data=run_data),
status_code=status.HTTP_200_OK,
)

Expand Down Expand Up @@ -285,6 +285,6 @@ async def remove_run(
raise RunNotFound(detail=str(e)).as_error(status.HTTP_404_NOT_FOUND) from e

return await PydanticResponse.create(
content=SimpleEmptyBody.construct(),
content=SimpleEmptyBody.model_construct(),
status_code=status.HTTP_200_OK,
)
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ async def create_run_command(
response_data = protocol_engine.state_view.commands.get(command.id)

return await PydanticResponse.create(
content=SimpleBody.construct(data=response_data),
content=SimpleBody.model_construct(data=response_data),
status_code=status.HTTP_201_CREATED,
)

Expand Down Expand Up @@ -259,7 +259,7 @@ async def get_run_commands(
current_command = run_data_manager.get_current_command(run_id=runId)

data = [
MaintenanceRunCommandSummary.construct(
MaintenanceRunCommandSummary.model_construct(
id=c.id,
key=c.key,
commandType=c.commandType,
Expand Down Expand Up @@ -294,7 +294,7 @@ async def get_run_commands(
)

return await PydanticResponse.create(
content=MultiBody.construct(data=data, meta=meta, links=links),
content=MultiBody.model_construct(data=data, meta=meta, links=links),
status_code=status.HTTP_200_OK,
)

Expand Down Expand Up @@ -336,6 +336,6 @@ async def get_run_command(
raise CommandNotFound(detail=str(e)).as_error(status.HTTP_404_NOT_FOUND) from e

return await PydanticResponse.create(
content=SimpleBody.construct(data=command),
content=SimpleBody.model_construct(data=command),
status_code=status.HTTP_200_OK,
)
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async def add_labware_offset(
log.info(f'Added labware offset "{added_offset.id}"' f' to run "{run.id}".')

return await PydanticResponse.create(
content=SimpleBody.construct(data=added_offset),
content=SimpleBody.model_construct(data=added_offset),
status_code=status.HTTP_201_CREATED,
)

Expand Down Expand Up @@ -88,8 +88,8 @@ async def add_labware_definition(
log.info(f'Added labware definition "{uri}"' f' to run "{run.id}".')

return PydanticResponse(
content=SimpleBody.construct(
data=LabwareDefinitionSummary.construct(definitionUri=uri)
content=SimpleBody.model_construct(
data=LabwareDefinitionSummary.model_construct(definitionUri=uri)
),
status_code=status.HTTP_201_CREATED,
)
4 changes: 2 additions & 2 deletions robot-server/robot_server/modules/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ async def get_attached_modules(
module_identity=module_identity,
live_data=mod.live_data,
usb_port=mod.usb_port,
module_offset=ModuleCalibrationData.construct(
module_offset=ModuleCalibrationData.model_construct(
offset=Vec3f(
x=calibrated.offset.x,
y=calibrated.offset.y,
Expand All @@ -83,7 +83,7 @@ async def get_attached_modules(
)

return await PydanticResponse.create(
content=SimpleMultiBody.construct(
content=SimpleMultiBody.model_construct(
data=response_data,
meta=MultiBodyMeta(cursor=0, totalLength=len(response_data)),
),
Expand Down
4 changes: 2 additions & 2 deletions robot-server/robot_server/persistence/pydantic.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Store Pydantic objects in the SQL database."""

from typing import Type, TypeVar
from pydantic import BaseModel, parse_raw_as
from pydantic import BaseModel


_BaseModelT = TypeVar("_BaseModelT", bound=BaseModel)
Expand All @@ -19,4 +19,4 @@ def pydantic_to_json(obj: BaseModel) -> str:

def json_to_pydantic(model: Type[_BaseModelT], json: str) -> _BaseModelT:
"""Parse a Pydantic object stored in the SQL database."""
return parse_raw_as(model, json)
return model.model_validate_json(json)
Loading

0 comments on commit 52b5899

Please sign in to comment.