Skip to content

Commit

Permalink
refactor(api): remove HardwareManager from protocol implementation (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mcous authored Feb 7, 2022
1 parent ab2e89a commit cb13eda
Show file tree
Hide file tree
Showing 31 changed files with 409 additions and 701 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ docs/build/
target/
.idea/
.setup_litter

# Accidental pipenv files in root
/Pipfile
/Pipfile.lock

# Testing
api/tests/opentrons/data/configs/
Expand Down
20 changes: 0 additions & 20 deletions Pipfile.lock

This file was deleted.

24 changes: 9 additions & 15 deletions api/mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ show_error_codes = True
warn_unused_configs = True
strict = True
# TODO(mc, 2021-09-12): work through and remove these exclusions
exclude = tests/opentrons/(hardware_control|protocol_api|protocols)/
exclude = tests/opentrons/(hardware_control|protocols/advanced_control|protocols/api_support|protocols/context|protocols/duration|protocols/execution|protocols/fixtures|protocols/geometry|protocols/models)/

[pydantic-mypy]
init_forbid_extra = True
Expand Down Expand Up @@ -82,20 +82,6 @@ disallow_untyped_defs = False
disallow_incomplete_defs = False
warn_return_any = False

# ~15 errors
[mypy-opentrons.execute]
disallow_untyped_defs = False
disallow_incomplete_defs = False
disallow_untyped_calls = False
no_implicit_optional = False

# ~25 errors
[mypy-opentrons.simulate]
disallow_untyped_defs = False
disallow_incomplete_defs = False
disallow_untyped_calls = False
no_implicit_optional = False

# ~5 errors
[mypy-opentrons.types]
disallow_untyped_defs = False
Expand Down Expand Up @@ -127,6 +113,14 @@ disallow_untyped_defs = False
disallow_untyped_calls = False
disallow_incomplete_defs = False

[mypy-tests.opentrons.protocol_api.*]
disallow_untyped_defs = False
disallow_untyped_calls = False
disallow_incomplete_defs = False

[mypy-tests.opentrons.protocols.*]
disallow_untyped_defs = False

# ~10 errors
[mypy-tests.opentrons.system.*]
disallow_untyped_defs = False
Expand Down
36 changes: 13 additions & 23 deletions api/src/opentrons/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,7 @@
import logging
import os
import sys
from typing import (
Any,
Callable,
Dict,
List,
Mapping,
Optional,
TextIO,
Union,
TYPE_CHECKING,
)
from typing import TYPE_CHECKING, Callable, Dict, List, Optional, TextIO, Union

from opentrons import protocol_api, __version__
from opentrons.config import IS_ROBOT, JUPYTER_NOTEBOOK_LABWARE_DIR
Expand All @@ -46,9 +36,9 @@

def get_protocol_api(
version: Union[str, APIVersion],
bundled_labware: Dict[str, "LabwareDefinition"] = None,
bundled_data: Dict[str, bytes] = None,
extra_labware: Dict[str, "LabwareDefinition"] = None,
bundled_labware: Optional[Dict[str, "LabwareDefinition"]] = None,
bundled_data: Optional[Dict[str, bytes]] = None,
extra_labware: Optional[Dict[str, "LabwareDefinition"]] = None,
) -> protocol_api.ProtocolContext:
"""
Build and return a ``protocol_api.ProtocolContext``
Expand Down Expand Up @@ -116,7 +106,7 @@ def get_protocol_api(
extra_labware = labware_from_paths([str(JUPYTER_NOTEBOOK_LABWARE_DIR)])

context_imp = ProtocolContextImplementation(
hardware=_THREAD_MANAGED_HW,
sync_hardware=_THREAD_MANAGED_HW.sync,
bundled_labware=bundled_labware,
bundled_data=bundled_data,
extra_labware=extra_labware,
Expand All @@ -126,7 +116,7 @@ def get_protocol_api(
context = protocol_api.ProtocolContext(
implementation=context_imp, api_version=checked_version
)
context_imp.get_hardware().hardware.cache_instruments()
context_imp.get_hardware().cache_instruments()
return context


Expand Down Expand Up @@ -213,10 +203,10 @@ def execute(
protocol_name: str,
propagate_logs: bool = False,
log_level: str = "warning",
emit_runlog: Callable[[Mapping[str, Any]], None] = None,
custom_labware_paths: List[str] = None,
custom_data_paths: List[str] = None,
):
emit_runlog: Optional[Callable[[command_types.CommandMessage], None]] = None,
custom_labware_paths: Optional[List[str]] = None,
custom_data_paths: Optional[List[str]] = None,
) -> None:
"""
Run the protocol itself.
Expand Down Expand Up @@ -319,11 +309,11 @@ def execute(
context.cleanup()


def make_runlog_cb():
def make_runlog_cb() -> Callable[[command_types.CommandMessage], None]:
level = 0
last_dollar = None

def _print_runlog(command: Dict[str, Any]):
def _print_runlog(command: command_types.CommandMessage) -> None:
nonlocal level
nonlocal last_dollar

Expand Down Expand Up @@ -382,7 +372,7 @@ def main() -> int:


@atexit.register
def _clear_cached_hardware_controller():
def _clear_cached_hardware_controller() -> None:
global _THREAD_MANAGED_HW
if _THREAD_MANAGED_HW:
_THREAD_MANAGED_HW.clean_up()
Expand Down
1 change: 1 addition & 0 deletions api/src/opentrons/hardware_control/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from .protocols import HardwareControlAPI

ThreadManagedHardware = ThreadManager[HardwareControlAPI]
SyncHardwareAPI = SynchronousAdapter[HardwareControlAPI]

__all__ = [
"API",
Expand Down
2 changes: 1 addition & 1 deletion api/src/opentrons/protocol_api/module_contexts.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ def _prepare_for_lid_move(self):
else:
ctx_impl = self._ctx._implementation
instr_impl = instr._implementation
hardware = ctx_impl.get_hardware().hardware
hardware = ctx_impl.get_hardware()

hardware.retract(instr_impl.get_mount())
high_point = hardware.current_position(instr_impl.get_mount())
Expand Down
Loading

0 comments on commit cb13eda

Please sign in to comment.