Skip to content

Commit

Permalink
refactor(api): Move old module package into legacy_api
Browse files Browse the repository at this point in the history
  • Loading branch information
sfoster1 committed Oct 4, 2018
1 parent a9c3d07 commit f956902
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 12 deletions.
8 changes: 5 additions & 3 deletions api/opentrons/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@
if ff.use_protocol_api_v2():
import protocol_api
from protocol_api.back_compat\
import robot, reset as bcreset, instruments, containers, labware
import robot, reset as bcreset, instruments, containers, labware,\
modules

def reset():
ctx = protocol_api.ProtocolContext()
bcreset(ctx)

else:
from .legacy_api.api import robot, reset, instruments, containers, labware
from .legacy_api.api\
import robot, reset, instruments, containers, labware, modules


__all__ = ['containers', 'instruments', 'labware', 'robot', 'reset',
'__version__']
'__version__', 'modules']
8 changes: 6 additions & 2 deletions api/opentrons/legacy_api/api.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from . import robot, instruments as inst, containers as cnt
from . import robot, instruments as inst, containers as cnt, modules
from .instruments import pipette_config

# Ignore the type here because well, this is exactly why this is the legacy_api
robot = robot.Robot() # type: ignore
modules.provide_singleton(robot)


def reset():
global robot
robot = robot.Robot()
modules.provide_singleton(robot)
return robot


Expand Down Expand Up @@ -259,5 +261,7 @@ def _retrieve_version_number(self, mount, expected_model_substring):
instruments = InstrumentsWrapper(robot)
containers = ContainersWrapper(robot)
labware = ContainersWrapper(robot)
modules.provide_labware(labware)

__all__ = ['containers', 'instruments', 'labware', 'robot', 'reset']

__all__ = ['containers', 'instruments', 'labware', 'robot', 'reset', 'modules']
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
import logging
import re
import asyncio
from opentrons.modules.magdeck import MagDeck
from opentrons.modules.tempdeck import TempDeck
from opentrons import robot, labware
from .magdeck import MagDeck
from .tempdeck import TempDeck

log = logging.getLogger(__name__)

Expand All @@ -25,11 +24,25 @@ class AbsentModuleError(Exception):
pass


_mod_robot = None
_mod_labware = None


def provide_singleton(robot):
global _mod_robot
_mod_robot = robot


def provide_labware(lw):
global _mod_labware
_mod_labware = lw


def load(name, slot):
module_instance = None
if name in SUPPORTED_MODULES:
if robot.is_simulating():
labware_instance = labware.load(name, slot)
if _mod_robot.is_simulating():
labware_instance = _mod_labware.load(name, slot)
module_class = SUPPORTED_MODULES.get(name)
module_instance = module_class(lw=labware_instance)
else:
Expand All @@ -39,13 +52,13 @@ def load(name, slot):
# accessor would then load the correct disambiguated module
# instance via the module's serial
matching_modules = [
module for module in robot.modules if isinstance(
module for module in _mod_robot.modules if isinstance(
module, SUPPORTED_MODULES.get(name)
)
]
if matching_modules:
module_instance = matching_modules[0]
labware_instance = labware.load(name, slot)
labware_instance = _mod_labware.load(name, slot)
module_instance.labware = labware_instance
else:
raise AbsentModuleError(
Expand Down
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions api/opentrons/protocol_api/back_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ def list(self, *args, **kwargs):
pass


class BCModules:
def __init__(self, ctx: 'papi.ProtocolContext') -> None:
self._ctx = ctx

def load(self, *args, **wargs):
pass


def reset(api: 'papi.ProtocolContext'):
global robot
global labware
Expand Down

0 comments on commit f956902

Please sign in to comment.