Skip to content
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

feat(api): register module instances on os events #4441

Merged
merged 25 commits into from
Nov 19, 2019
Merged

Conversation

b-cooper
Copy link
Contributor

overview

Previously, the hardware controller only became aware of underlying connected hardware modules when
it was told to look via an http endpoint (only effectively used by the run app). In order to remove
this unnecessary reliance, the hardware controller now watches the filesystem for changes using
aionotify (a thin python wrapper of linux util). Changes to the physically connected modules should
now be instantly reflected in the hardware controllers attached modules regardless of whether the
hardware controller is observed by a third party or not. No more Schrödinger's modules

re #3580

changelog

  • attached modules now live on hardware_controller.API.attached_modules as a list of AbstractModule instances
  • a few tests that call build_hardware_controller are now skipped in case aionotify/ inotify is not present (non-linux environments)

review requests

  • ensure modules still appear attached to robot in APIv1 and APIv2 on the run app
  • ensure modules function in a protocol when in APIv1 and APIv2 on the run app
  • ensure modules can still be controlled outside of a protocol when in APIv2 on the run app

@b-cooper b-cooper added feature Ticket is a feature request / PR introduces a feature api Affects the `api` project ready for review labels Nov 12, 2019
Previously, the hardware controller only became aware of underlying connected hardware modules when
it was told to look via an http endpoint (only effectively used by the run app). In order to remove
this unnecessary reliance, the hardware controller now watches the filesystem for changes using
aionotify (a thin python wrapper of linux util). Changes to the physically connected modules should
now be instantly reflected in the hardware controllers attached modules regardless of whether the
hardware controller is observed by a third party or not. No more Schrödinger's modules

re #3580
Copy link
Member

@sfoster1 sfoster1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline comments. Also,

  • We need to specify the new aionotify dependency in our pipfile specs (for devs) and in our install_requires in setup.py for pypi, presumably gated around linux
  • Bit concerned about the flow around updating modules when they switch ports, but I haven't tested yet
  • We also need to test just what happens when you create a hardware controller on windows, since manufacturing does this all the time (or will): it should run, although it's ok if it's degraded

api/src/opentrons/hardware_control/__init__.py Outdated Show resolved Hide resolved
api/src/opentrons/hardware_control/__init__.py Outdated Show resolved Hide resolved
api/src/opentrons/hardware_control/__init__.py Outdated Show resolved Hide resolved
api/src/opentrons/hardware_control/controller.py Outdated Show resolved Hide resolved
api/src/opentrons/hardware_control/controller.py Outdated Show resolved Hide resolved
api/src/opentrons/hardware_control/modules/__init__.py Outdated Show resolved Hide resolved
api/src/opentrons/hardware_control/modules/__init__.py Outdated Show resolved Hide resolved
api/src/opentrons/hardware_control/simulator.py Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Nov 15, 2019

Codecov Report

Merging #4441 into edge will increase coverage by 1.14%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##             edge    #4441      +/-   ##
==========================================
+ Coverage   55.47%   56.62%   +1.14%     
==========================================
  Files         904      906       +2     
  Lines       26119    28415    +2296     
==========================================
+ Hits        14490    16089    +1599     
- Misses      11629    12326     +697
Impacted Files Coverage Δ
.../protocol_api/legacy_wrapper/instrument_wrapper.py 28.69% <0%> (-34.35%) ⬇️
opentrons/hardware_control/modules/__init__.py 42.1% <0%> (-19.9%) ⬇️
opentrons/hardware_control/modules/update.py 21.21% <0%> (-19%) ⬇️
...designer/src/components/KnowledgeBaseLink/index.js 50% <0%> (-16.67%) ⬇️
opentrons/legacy_api/modules/__init__.py 67.3% <0%> (-13.47%) ⬇️
opentrons/hardware_control/controller.py 46.51% <0%> (-5.01%) ⬇️
opentrons/hardware_control/modules/tempdeck.py 88.05% <0%> (-4.75%) ⬇️
opentrons/hardware_control/adapters.py 70.7% <0%> (-3.63%) ⬇️
opentrons/protocol_api/legacy_wrapper/api.py 67.91% <0%> (-2.22%) ⬇️
...tocol-designer/src/file-data/selectors/commands.js 20% <0%> (-1.22%) ⬇️
... and 31 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5135da9...80b582f. Read the comment docs.

@b-cooper b-cooper requested a review from sfoster1 November 15, 2019 20:59
Pipfile.lock Outdated Show resolved Hide resolved
api/setup.py Show resolved Hide resolved
Copy link
Member

@sfoster1 sfoster1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple more inline changes

path='/dev',
flags=(aionotify.Flags.CREATE | aionotify.Flags.DELETE))
except AttributeError:
MODULE_LOG.info(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should definitely be warning level

MODULE_LOG.info(f'Module Removed: {maybe_module_at_port}')
if maybe_module_at_port is not None and \
aionotify.Flags.CREATE in flags:
await register_modules(new_modules=[maybe_module_at_port])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we coalesce these? could this happen with

  • events for more than one module
  • create and then delete event for a module
  • delete and then create event for a module

@@ -201,3 +228,6 @@ def probe(self, axis: str, distance: float) -> Dict[str, float]:
self.pause()
await asyncio.sleep(duration_s)
self.resume()

def __exit__(self, exc_type, exc_value, traceback):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this wants to be __del__ (https://docs.python.org/3/reference/datamodel.html#object.__del__), __exit__ (https://docs.python.org/3/reference/datamodel.html#object.__exit__) is for context managers, aka things you use in a with statement

api/src/opentrons/hardware_control/types.py Outdated Show resolved Hide resolved
Copy link
Member

@sfoster1 sfoster1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more little issue

@@ -201,3 +234,6 @@ def probe(self, axis: str, distance: float) -> Dict[str, float]:
self.pause()
await asyncio.sleep(duration_s)
self.resume()

def __del__(self, exc_type, exc_value, traceback):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take a look at the docs again (https://docs.python.org/3/reference/datamodel.html#object.__del__), this can't take any arguments unfortunately

@b-cooper b-cooper requested a review from sfoster1 November 19, 2019 16:49
Copy link
Member

@sfoster1 sfoster1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Affects the `api` project feature Ticket is a feature request / PR introduces a feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants