Skip to content

Commit

Permalink
refactor(api): Remove opentrons_hardware from ot3api (#14328)
Browse files Browse the repository at this point in the history
* refactor(api): make ot3api always importable

While OT3API is only used to control hardware on a flex (where the
opentrons_hardware package is always available), it can also be used to
simulate both in the context of the robot or desktop app (similar) and
on installs from pypi, where opentrons_hardware is _not_ available
because it is not intended to work on any platform other than linux.

We can fix this by making sure that opentrons_hardware doesn't need to
be imported in any protocol simulation path, by making sure that any
imports from opentrons_hardware happen from (eventually) ot3controller,
and ot3controller is conditionally imported when you try and build a
hardware-controlling OT3API.

That is generally pretty easy but it requires some refactors. For
instance,
- Planning moves needs to happen inside ot3controller
- The backend needs to be the owner of the status bar controller and the
estop controller and offer passthrough methods to the API

These shouldn't change any functionality.

Finally, to make sure this doesn't happen again, add a test to try and
import and build a simulating OT3API in the no-hardware case.

* refactor(api): type ot3 hardware control tests

Next step in gradual typing! And fix up the changes required from the
backend refactor while we're at it.

Closes RSS-402
  • Loading branch information
sfoster1 authored Jan 19, 2024
1 parent 1fca6a0 commit 4ef48fb
Show file tree
Hide file tree
Showing 28 changed files with 1,260 additions and 715 deletions.
2 changes: 1 addition & 1 deletion 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/test_.*py|hardware_control/integration/|hardware_control/emulation/|hardware_control/modules/|protocols/advanced_control/|protocols/api_support/|protocols/duration/|protocols/execution/|protocols/fixtures/|protocols/geometry/)
exclude = tests/opentrons/(hardware_control/test_(?!ot3).*py|hardware_control/integration/|hardware_control/emulation/|hardware_control/modules/|protocols/advanced_control/|protocols/api_support/|protocols/duration/|protocols/execution/|protocols/fixtures/|protocols/geometry/)

[pydantic-mypy]
init_forbid_extra = True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
EstopAttachLocation,
EstopStateNotification,
HardwareEventHandler,
HardwareEventUnsubscriber,
)


Expand Down Expand Up @@ -51,10 +52,12 @@ def __del__(self) -> None:
if self._detector is not None:
self._detector.remove_listener(self.detector_listener)

def add_listener(self, listener: HardwareEventHandler) -> None:
def add_listener(self, listener: HardwareEventHandler) -> HardwareEventUnsubscriber:
"""Add a hardware event listener for estop event changes."""
if listener not in self._listeners:
self._listeners.append(listener)
return lambda: self.remove_listener(listener)
return lambda: None

def remove_listener(self, listener: HardwareEventHandler) -> None:
"""Remove an existing hardware event listener for estop detector changes."""
Expand Down
Loading

0 comments on commit 4ef48fb

Please sign in to comment.