diff --git a/robot-server/Makefile b/robot-server/Makefile index 57cb578b56d2..e8590254b29e 100755 --- a/robot-server/Makefile +++ b/robot-server/Makefile @@ -71,7 +71,7 @@ clean_all_cmd = $(clean_cmd) dist # probably POSIX-only. dev_port ?= "31950" dev_host ?= "localhost" -run_dev ?= uvicorn "robot_server:app" --host $(dev_host) --port $(dev_port) --ws wsproto --lifespan on --reload +run_dev ?= uvicorn "robot_server.app:app" --host $(dev_host) --port $(dev_port) --ws wsproto --lifespan on --reload .PHONY: all all: clean sdist wheel diff --git a/robot-server/opentrons-robot-server.service b/robot-server/opentrons-robot-server.service index 095c4fb39bb5..48648658cecc 100644 --- a/robot-server/opentrons-robot-server.service +++ b/robot-server/opentrons-robot-server.service @@ -18,7 +18,7 @@ Type=notify # /run/aiohttp.sock matches where our reverse proxy expects to find us. # It refers to aiohttp even though this server doesn't use that framework # for historical reasons. -ExecStart=uvicorn robot_server:app --uds /run/aiohttp.sock --ws wsproto --lifespan on +ExecStart=uvicorn robot_server.app:app --uds /run/aiohttp.sock --ws wsproto --lifespan on Environment=OT_SMOOTHIE_ID=AMA Environment=RUNNING_ON_PI=true diff --git a/robot-server/robot_server/__init__.py b/robot-server/robot_server/__init__.py index 4d5dcbf1ddce..329cf0c1e83d 100644 --- a/robot-server/robot_server/__init__.py +++ b/robot-server/robot_server/__init__.py @@ -2,9 +2,3 @@ This server provides the main control interface for an Opentrons robot. """ - -from .app_setup import app - -__all__ = [ - "app", -] diff --git a/robot-server/robot_server/app.py b/robot-server/robot_server/app.py new file mode 100644 index 000000000000..4a229be1abd0 --- /dev/null +++ b/robot-server/robot_server/app.py @@ -0,0 +1,10 @@ +"""The public export of the server's ASGI app object. + +For import speed, we do this from a dedicated file instead of from the top-level +__init__.py. We want worker processes and tests to be able to import specific things +deep in robot_server without having to import this ASGI app and all of its dependencies. +""" + +from .app_setup import app + +__all__ = ["app"] diff --git a/robot-server/robot_server/protocols/__init__.py b/robot-server/robot_server/protocols/__init__.py index 34bdaaebe681..60f3ae5dc5a6 100644 --- a/robot-server/robot_server/protocols/__init__.py +++ b/robot-server/robot_server/protocols/__init__.py @@ -1,16 +1 @@ """Protocol file upload and management.""" -from .router import protocols_router, ProtocolNotFound -from .dependencies import get_protocol_store -from .protocol_store import ProtocolStore, ProtocolResource, ProtocolNotFoundError - -__all__ = [ - # main protocols router - "protocols_router", - # common error response details - "ProtocolNotFound", - # protocol state management - "get_protocol_store", - "ProtocolStore", - "ProtocolResource", - "ProtocolNotFoundError", -] diff --git a/robot-server/robot_server/router.py b/robot-server/robot_server/router.py index 4739c4d84cec..2398e9fe1616 100644 --- a/robot-server/robot_server/router.py +++ b/robot-server/robot_server/router.py @@ -11,7 +11,7 @@ from .instruments import instruments_router from .maintenance_runs.router import maintenance_runs_router from .modules import modules_router -from .protocols import protocols_router +from .protocols.router import protocols_router from .robot.router import robot_router from .runs import runs_router from .service.labware.router import router as labware_router diff --git a/robot-server/robot_server/runs/engine_store.py b/robot-server/robot_server/runs/engine_store.py index 350d5bc694c4..d938fbbbe25e 100644 --- a/robot-server/robot_server/runs/engine_store.py +++ b/robot-server/robot_server/runs/engine_store.py @@ -31,7 +31,7 @@ create_protocol_engine, ) -from robot_server.protocols import ProtocolResource +from robot_server.protocols.protocol_store import ProtocolResource from opentrons.protocol_engine.types import DeckConfigurationType diff --git a/robot-server/robot_server/runs/router/base_router.py b/robot-server/robot_server/runs/router/base_router.py index d7c1ea1bc59b..3edd9a342bae 100644 --- a/robot-server/robot_server/runs/router/base_router.py +++ b/robot-server/robot_server/runs/router/base_router.py @@ -27,12 +27,12 @@ PydanticResponse, ) -from robot_server.protocols import ( +from robot_server.protocols.dependencies import get_protocol_store +from robot_server.protocols.protocol_store import ( ProtocolStore, - ProtocolNotFound, ProtocolNotFoundError, - get_protocol_store, ) +from robot_server.protocols.router import ProtocolNotFound from ..run_models import RunNotFoundError from ..run_auto_deleter import RunAutoDeleter diff --git a/robot-server/robot_server/runs/run_data_manager.py b/robot-server/robot_server/runs/run_data_manager.py index be62c7b704f8..acf0ddec6c4a 100644 --- a/robot-server/robot_server/runs/run_data_manager.py +++ b/robot-server/robot_server/runs/run_data_manager.py @@ -13,7 +13,7 @@ Command, ) -from robot_server.protocols import ProtocolResource +from robot_server.protocols.protocol_store import ProtocolResource from robot_server.service.task_runner import TaskRunner from robot_server.service.notifications import RunsPublisher diff --git a/robot-server/robot_server/runs/run_store.py b/robot-server/robot_server/runs/run_store.py index 40e59143e766..aa65ce197044 100644 --- a/robot-server/robot_server/runs/run_store.py +++ b/robot-server/robot_server/runs/run_store.py @@ -20,7 +20,7 @@ sqlite_rowid, ) from robot_server.persistence.pydantic import json_to_pydantic, pydantic_to_json -from robot_server.protocols import ProtocolNotFoundError +from robot_server.protocols.protocol_store import ProtocolNotFoundError from robot_server.service.notifications import RunsPublisher from .action_models import RunAction, RunActionType diff --git a/robot-server/tests/conftest.py b/robot-server/tests/conftest.py index 3014c922faa7..f3a5ce2761e3 100644 --- a/robot-server/tests/conftest.py +++ b/robot-server/tests/conftest.py @@ -36,7 +36,7 @@ from opentrons.protocol_api import labware from opentrons.types import Point, Mount -from robot_server import app +from robot_server.app import app from robot_server.hardware import get_hardware, get_ot2_hardware from robot_server.versioning import API_VERSION_HEADER, LATEST_API_VERSION_HEADER_VALUE from robot_server.service.session.manager import SessionManager diff --git a/robot-server/tests/integration/dev_server.py b/robot-server/tests/integration/dev_server.py index ab774cc750b7..f549a4752e85 100644 --- a/robot-server/tests/integration/dev_server.py +++ b/robot-server/tests/integration/dev_server.py @@ -79,7 +79,7 @@ def start(self) -> None: "robot_server", "-m", "uvicorn", - "robot_server:app", + "robot_server.app:app", "--host", "localhost", "--port", diff --git a/robot-server/tests/runs/router/conftest.py b/robot-server/tests/runs/router/conftest.py index f7d1f0fead6c..96b0bb578e7d 100644 --- a/robot-server/tests/runs/router/conftest.py +++ b/robot-server/tests/runs/router/conftest.py @@ -2,7 +2,7 @@ import pytest from decoy import Decoy -from robot_server.protocols import ProtocolStore +from robot_server.protocols.protocol_store import ProtocolStore from robot_server.runs.run_auto_deleter import RunAutoDeleter from robot_server.runs.run_store import RunStore from robot_server.runs.engine_store import EngineStore diff --git a/robot-server/tests/runs/router/test_base_router.py b/robot-server/tests/runs/router/test_base_router.py index 0abe559b8432..c4ba00657c07 100644 --- a/robot-server/tests/runs/router/test_base_router.py +++ b/robot-server/tests/runs/router/test_base_router.py @@ -17,10 +17,10 @@ ResourceLink, ) -from robot_server.protocols import ( - ProtocolStore, - ProtocolResource, +from robot_server.protocols.protocol_store import ( ProtocolNotFoundError, + ProtocolResource, + ProtocolStore, ) from robot_server.runs.run_auto_deleter import RunAutoDeleter diff --git a/robot-server/tests/runs/test_engine_store.py b/robot-server/tests/runs/test_engine_store.py index bd8ef9b36786..1bf746321397 100644 --- a/robot-server/tests/runs/test_engine_store.py +++ b/robot-server/tests/runs/test_engine_store.py @@ -18,7 +18,7 @@ ) from opentrons.protocol_reader import ProtocolReader, ProtocolSource -from robot_server.protocols import ProtocolResource +from robot_server.protocols.protocol_store import ProtocolResource from robot_server.runs.engine_store import ( EngineStore, EngineConflictError, diff --git a/robot-server/tests/runs/test_run_data_manager.py b/robot-server/tests/runs/test_run_data_manager.py index bc8f9ad16cb9..cabaa09ae052 100644 --- a/robot-server/tests/runs/test_run_data_manager.py +++ b/robot-server/tests/runs/test_run_data_manager.py @@ -21,7 +21,7 @@ LabwareOffset, ) -from robot_server.protocols import ProtocolResource +from robot_server.protocols.protocol_store import ProtocolResource from robot_server.runs.engine_store import EngineStore, EngineConflictError from robot_server.runs.run_data_manager import RunDataManager, RunNotCurrentError from robot_server.runs.run_models import Run, RunNotFoundError diff --git a/robot-server/tests/service/legacy/routers/test_settings.py b/robot-server/tests/service/legacy/routers/test_settings.py index 58bcfefffe0d..27a930617fd6 100644 --- a/robot-server/tests/service/legacy/routers/test_settings.py +++ b/robot-server/tests/service/legacy/routers/test_settings.py @@ -18,7 +18,7 @@ from opentrons_shared_data.robot.dev_types import RobotTypeEnum -from robot_server import app +from robot_server.app import app from robot_server.deck_configuration.fastapi_dependencies import ( get_deck_configuration_store_failsafe, )