Skip to content

Commit

Permalink
perf(robot-server): Remove slow re-exports from __init__.py and proto…
Browse files Browse the repository at this point in the history
…cols/__init__.py (#14480)
  • Loading branch information
SyntaxColoring authored and TamarZanzouri committed Feb 16, 2024
1 parent 1a55549 commit 49f1e7f
Show file tree
Hide file tree
Showing 17 changed files with 28 additions and 39 deletions.
2 changes: 1 addition & 1 deletion robot-server/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion robot-server/opentrons-robot-server.service
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions robot-server/robot_server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,3 @@
This server provides the main control interface for an Opentrons robot.
"""

from .app_setup import app

__all__ = [
"app",
]
10 changes: 10 additions & 0 deletions robot-server/robot_server/app.py
Original file line number Diff line number Diff line change
@@ -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"]
15 changes: 0 additions & 15 deletions robot-server/robot_server/protocols/__init__.py
Original file line number Diff line number Diff line change
@@ -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",
]
2 changes: 1 addition & 1 deletion robot-server/robot_server/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion robot-server/robot_server/runs/engine_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
6 changes: 3 additions & 3 deletions robot-server/robot_server/runs/router/base_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion robot-server/robot_server/runs/run_data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion robot-server/robot_server/runs/run_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion robot-server/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion robot-server/tests/integration/dev_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def start(self) -> None:
"robot_server",
"-m",
"uvicorn",
"robot_server:app",
"robot_server.app:app",
"--host",
"localhost",
"--port",
Expand Down
2 changes: 1 addition & 1 deletion robot-server/tests/runs/router/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions robot-server/tests/runs/router/test_base_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion robot-server/tests/runs/test_engine_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion robot-server/tests/runs/test_run_data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion robot-server/tests/service/legacy/routers/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down

0 comments on commit 49f1e7f

Please sign in to comment.