Skip to content

Commit

Permalink
opentrons api can have a little legacy as a treat
Browse files Browse the repository at this point in the history
  • Loading branch information
jbleon95 committed May 2, 2024
1 parent a672a9a commit 64a3a20
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 39 deletions.
22 changes: 11 additions & 11 deletions api/src/opentrons/protocol_runner/legacy_command_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
from opentrons.protocol_api import InstrumentContext
from opentrons.protocol_api.core.legacy.deck import FIXED_TRASH_ID
from opentrons.protocol_api.core.legacy.load_info import (
LoadInfo,
LabwareLoadInfo,
InstrumentLoadInfo,
ModuleLoadInfo,
LoadInfo as LegacyLoadInfo,
LabwareLoadInfo as LegacyLabwareLoadInfo,
InstrumentLoadInfo as LegacyInstrumentLoadInfo,
ModuleLoadInfo as LegacyModuleLoadInfo,
)
from opentrons.protocol_engine import (
ProtocolEngineError,
Expand Down Expand Up @@ -283,13 +283,13 @@ def map_command( # noqa: C901

return results

def map_equipment_load(self, load_info: LoadInfo) -> List[pe_actions.Action]:
def map_equipment_load(self, load_info: LegacyLoadInfo) -> List[pe_actions.Action]:
"""Map a labware, instrument (pipette), or module load to a PE command."""
if isinstance(load_info, LabwareLoadInfo):
if isinstance(load_info, LegacyLabwareLoadInfo):
return self._map_labware_load(load_info)
elif isinstance(load_info, InstrumentLoadInfo):
elif isinstance(load_info, LegacyInstrumentLoadInfo):
return self._map_instrument_load(load_info)
elif isinstance(load_info, ModuleLoadInfo):
elif isinstance(load_info, LegacyModuleLoadInfo):
return self._map_module_load(load_info)

def _build_initial_command(
Expand Down Expand Up @@ -592,7 +592,7 @@ def _build_blow_out(
return custom_create, custom_running

def _map_labware_load(
self, labware_load_info: LabwareLoadInfo
self, labware_load_info: LegacyLabwareLoadInfo
) -> List[pe_actions.Action]:
"""Map a legacy labware load to a ProtocolEngine command."""
now = ModelUtils.get_timestamp()
Expand Down Expand Up @@ -660,7 +660,7 @@ def _map_labware_load(

def _map_instrument_load(
self,
instrument_load_info: InstrumentLoadInfo,
instrument_load_info: LegacyInstrumentLoadInfo,
) -> List[pe_actions.Action]:
"""Map a legacy instrument (pipette) load to a ProtocolEngine command.
Expand Down Expand Up @@ -719,7 +719,7 @@ def _map_instrument_load(
return [queue_action, run_action, succeed_action]

def _map_module_load(
self, module_load_info: ModuleLoadInfo
self, module_load_info: LegacyModuleLoadInfo
) -> List[pe_actions.Action]:
"""Map a legacy module load to a Protocol Engine command."""
now = ModelUtils.get_timestamp()
Expand Down
4 changes: 2 additions & 2 deletions api/src/opentrons/protocol_runner/legacy_context_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ def handle_action(self, action: pe_actions.Action) -> None:
pass

def _handle_legacy_command(self, command: LegacyCommand) -> None:
"""Handle a command reported by the APIv2 protocol.
"""Handle a command reported by the legacy APIv2 protocol.
Used as a broker callback, so this will run in the APIv2 protocol's thread.
"""
pe_actions = self._legacy_command_mapper.map_command(command=command)
self._actions_to_dispatch.put(pe_actions)

def _handle_equipment_loaded(self, load_info: LoadInfo) -> None:
"""Handle an equipment load reported by the APIv2 protocol.
"""Handle an equipment load reported by the legacy APIv2 protocol.
Used as a broker callback, so this will run in the APIv2 protocol's thread.
"""
Expand Down
10 changes: 5 additions & 5 deletions api/src/opentrons/protocol_runner/protocol_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from .python_protocol_wrappers import (
LEGACY_PYTHON_API_VERSION_CUTOFF,
LEGACY_JSON_SCHEMA_VERSION_CUTOFF,
PythonProtocolFileReader,
PythonAndLegacyFileReader,
ProtocolContextCreator,
PythonProtocolExecutor,
)
Expand Down Expand Up @@ -136,7 +136,7 @@ def __init__(
protocol_engine: ProtocolEngine,
hardware_api: HardwareControlAPI,
task_queue: Optional[TaskQueue] = None,
python_protocol_file_reader: Optional[PythonProtocolFileReader] = None,
python_and_legacy_file_reader: Optional[PythonAndLegacyFileReader] = None,
protocol_context_creator: Optional[ProtocolContextCreator] = None,
python_protocol_executor: Optional[PythonProtocolExecutor] = None,
post_run_hardware_state: PostRunHardwareState = PostRunHardwareState.HOME_AND_STAY_ENGAGED,
Expand All @@ -146,7 +146,7 @@ def __init__(
super().__init__(protocol_engine)
self._hardware_api = hardware_api
self._protocol_file_reader = (
python_protocol_file_reader or PythonProtocolFileReader()
python_and_legacy_file_reader or PythonAndLegacyFileReader()
)
self._protocol_context_creator = (
protocol_context_creator
Expand Down Expand Up @@ -422,7 +422,7 @@ def create_protocol_runner(
task_queue: Optional[TaskQueue] = None,
json_file_reader: Optional[JsonFileReader] = None,
json_translator: Optional[JsonTranslator] = None,
python_protocol_file_reader: Optional[PythonProtocolFileReader] = None,
python_and_legacy_file_reader: Optional[PythonAndLegacyFileReader] = None,
protocol_context_creator: Optional[ProtocolContextCreator] = None,
python_protocol_executor: Optional[PythonProtocolExecutor] = None,
post_run_hardware_state: PostRunHardwareState = PostRunHardwareState.HOME_AND_STAY_ENGAGED,
Expand All @@ -448,7 +448,7 @@ def create_protocol_runner(
protocol_engine=protocol_engine,
hardware_api=hardware_api,
task_queue=task_queue,
python_protocol_file_reader=python_protocol_file_reader,
python_and_legacy_file_reader=python_and_legacy_file_reader,
protocol_context_creator=protocol_context_creator,
python_protocol_executor=python_protocol_executor,
post_run_hardware_state=post_run_hardware_state,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
LEGACY_JSON_SCHEMA_VERSION_CUTOFF = 6


class PythonProtocolFileReader:
class PythonAndLegacyFileReader:
"""Interface to read Protocol API v2 protocols prior to execution."""

@staticmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
from opentrons.hardware_control.modules.types import TemperatureModuleModel
from opentrons.legacy_commands.types import CommentMessage, PauseMessage, CommandMessage
from opentrons.protocol_api.core.legacy.load_info import (
LabwareLoadInfo,
InstrumentLoadInfo,
ModuleLoadInfo,
LabwareLoadInfo as LegacyLabwareLoadInfo,
InstrumentLoadInfo as LegacyInstrumentLoadInfo,
ModuleLoadInfo as LegacyModuleLoadInfo,
)
from opentrons.protocol_engine import (
DeckSlotLocation,
Expand Down Expand Up @@ -270,7 +270,7 @@ def test_command_stack() -> None:

def test_map_labware_load(minimal_labware_def: LabwareDefinition) -> None:
"""It should correctly map a labware load."""
input = LabwareLoadInfo(
input = LegacyLabwareLoadInfo(
labware_definition=minimal_labware_def,
labware_namespace="some_namespace",
labware_load_name="some_load_name",
Expand Down Expand Up @@ -334,7 +334,7 @@ def test_map_labware_load(minimal_labware_def: LabwareDefinition) -> None:
def test_map_instrument_load(decoy: Decoy) -> None:
"""It should correctly map an instrument load."""
pipette_dict = cast(PipetteDict, {"pipette_id": "fizzbuzz"})
input = InstrumentLoadInfo(
input = LegacyInstrumentLoadInfo(
instrument_load_name="p1000_single_gen2",
mount=Mount.LEFT,
pipette_dict=pipette_dict,
Expand Down Expand Up @@ -395,7 +395,7 @@ def test_map_module_load(
) -> None:
"""It should correctly map a module load."""
test_definition = ModuleDefinition.parse_obj(minimal_module_def)
input = ModuleLoadInfo(
input = LegacyModuleLoadInfo(
requested_model=TemperatureModuleModel.TEMPERATURE_V1,
loaded_model=TemperatureModuleModel.TEMPERATURE_V2,
deck_slot=DeckSlotName.SLOT_1,
Expand Down Expand Up @@ -454,7 +454,7 @@ def test_map_module_load(

def test_map_module_labware_load(minimal_labware_def: LabwareDefinition) -> None:
"""It should correctly map a labware load on module."""
load_input = LabwareLoadInfo(
load_input = LegacyLabwareLoadInfo(
labware_definition=minimal_labware_def,
labware_namespace="some_namespace",
labware_load_name="some_load_name",
Expand Down
26 changes: 13 additions & 13 deletions api/tests/opentrons/protocol_runner/test_protocol_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
from opentrons.protocol_runner.json_translator import JsonTranslator
from opentrons.protocol_runner.legacy_context_plugin import LegacyContextPlugin
from opentrons.protocol_runner.python_protocol_wrappers import (
PythonProtocolFileReader,
PythonAndLegacyFileReader,
ProtocolContextCreator,
PythonProtocolExecutor,
)
Expand Down Expand Up @@ -85,9 +85,9 @@ def json_translator(decoy: Decoy) -> JsonTranslator:


@pytest.fixture
def python_protocol_file_reader(decoy: Decoy) -> PythonProtocolFileReader:
"""Get a mocked out PythonProtocolFileReader dependency."""
return decoy.mock(cls=PythonProtocolFileReader)
def python_and_legacy_file_reader(decoy: Decoy) -> PythonAndLegacyFileReader:
"""Get a mocked out PythonAndLegacyFileReader dependency."""
return decoy.mock(cls=PythonAndLegacyFileReader)


@pytest.fixture
Expand Down Expand Up @@ -137,7 +137,7 @@ def python_runner_subject(
protocol_engine: ProtocolEngine,
hardware_api: HardwareAPI,
task_queue: TaskQueue,
python_protocol_file_reader: PythonProtocolFileReader,
python_and_legacy_file_reader: PythonAndLegacyFileReader,
protocol_context_creator: ProtocolContextCreator,
python_protocol_executor: PythonProtocolExecutor,
) -> PythonAndLegacyRunner:
Expand All @@ -146,7 +146,7 @@ def python_runner_subject(
protocol_engine=protocol_engine,
hardware_api=hardware_api,
task_queue=task_queue,
python_protocol_file_reader=python_protocol_file_reader,
python_and_legacy_file_reader=python_and_legacy_file_reader,
protocol_context_creator=protocol_context_creator,
python_protocol_executor=python_protocol_executor,
)
Expand Down Expand Up @@ -183,7 +183,7 @@ def test_create_protocol_runner(
task_queue: TaskQueue,
json_file_reader: JsonFileReader,
json_translator: JsonTranslator,
python_protocol_file_reader: PythonProtocolFileReader,
python_and_legacy_file_reader: PythonAndLegacyFileReader,
protocol_context_creator: ProtocolContextCreator,
python_protocol_executor: PythonProtocolExecutor,
config: Optional[Union[JsonProtocolConfig, PythonProtocolConfig]],
Expand Down Expand Up @@ -522,7 +522,7 @@ async def test_load_json_runner(

async def test_load_legacy_python(
decoy: Decoy,
python_protocol_file_reader: PythonProtocolFileReader,
python_and_legacy_file_reader: PythonAndLegacyFileReader,
protocol_context_creator: ProtocolContextCreator,
python_protocol_executor: PythonProtocolExecutor,
task_queue: TaskQueue,
Expand Down Expand Up @@ -563,7 +563,7 @@ async def test_load_legacy_python(
await protocol_reader.extract_labware_definitions(legacy_protocol_source)
).then_return([labware_definition])
decoy.when(
python_protocol_file_reader.read(
python_and_legacy_file_reader.read(
protocol_source=legacy_protocol_source,
labware_definitions=[labware_definition],
python_parse_mode=PythonParseMode.ALLOW_LEGACY_METADATA_AND_REQUIREMENTS,
Expand Down Expand Up @@ -612,7 +612,7 @@ async def test_load_legacy_python(

async def test_load_python_with_pe_papi_core(
decoy: Decoy,
python_protocol_file_reader: PythonProtocolFileReader,
python_and_legacy_file_reader: PythonAndLegacyFileReader,
protocol_context_creator: ProtocolContextCreator,
protocol_engine: ProtocolEngine,
python_runner_subject: PythonAndLegacyRunner,
Expand Down Expand Up @@ -647,7 +647,7 @@ async def test_load_python_with_pe_papi_core(
await protocol_reader.extract_labware_definitions(protocol_source)
).then_return([])
decoy.when(
python_protocol_file_reader.read(
python_and_legacy_file_reader.read(
protocol_source=protocol_source,
labware_definitions=[],
python_parse_mode=PythonParseMode.ALLOW_LEGACY_METADATA_AND_REQUIREMENTS,
Expand All @@ -672,7 +672,7 @@ async def test_load_python_with_pe_papi_core(

async def test_load_legacy_json(
decoy: Decoy,
python_protocol_file_reader: PythonProtocolFileReader,
python_and_legacy_file_reader: PythonAndLegacyFileReader,
protocol_context_creator: ProtocolContextCreator,
python_protocol_executor: PythonProtocolExecutor,
task_queue: TaskQueue,
Expand Down Expand Up @@ -708,7 +708,7 @@ async def test_load_legacy_json(
await protocol_reader.extract_labware_definitions(legacy_protocol_source)
).then_return([labware_definition])
decoy.when(
python_protocol_file_reader.read(
python_and_legacy_file_reader.read(
protocol_source=legacy_protocol_source,
labware_definitions=[labware_definition],
python_parse_mode=PythonParseMode.ALLOW_LEGACY_METADATA_AND_REQUIREMENTS,
Expand Down

0 comments on commit 64a3a20

Please sign in to comment.