Skip to content

Commit

Permalink
fix(opentrons-shared-data): fix performance module not being recogniz…
Browse files Browse the repository at this point in the history
…ed (#14990)

# Overview

Fixes https://opentrons.atlassian.net/browse/RQA-2623

performance directory was missing an `__init__.py`

# Test Plan

- I added a test just to import the module and create one of the objects
inside the dev_types.py. The issue is that the tests don't run against
the built version of the package. I built the app and everything imports
correctly
- I cannot test that opentrons_shared_data is being utilized correctly
on the robot until I have a built buildroot image. Because currently my
robot and app have different versions (due to the dev build) so the app
will not let me trigger an analysis.
- I instead pushed opentrons-shared-data to my robot and verified that
the performance module existed in
`/usr/lib/python3.10/site-packages/opentrons_shared_data`. But I can't
test that the imports actually work until I have the system image and
the app together

# Changelog

- Added `__init__.py` to performance directory to tell python to import
it as a module
- Reorganized performance_helpers.py to not have an import error

# Review requests

- Nothing to block this fix, but what should be done to make sure this
doesn't happen again? This is a weird packaging thing that doesn't show
up when running dev or CI testing.
- I wonder if there is a smoke test we can perform automatically just to
make sure everything imports correctly? Running opentrons.simulate
against the actual built package would have caught this


# Risk assessment

Medium, I mean I can't break it any worse than I already did
  • Loading branch information
DerekMaggio authored and Carlos-fernandez committed May 20, 2024
1 parent 2a556b1 commit ed217ba
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 17 deletions.
34 changes: 17 additions & 17 deletions api/src/opentrons/util/performance_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,6 @@
)


def _handle_package_import() -> Type[SupportsTracking]:
"""Handle the import of the performance_metrics package.
If the package is not available, return a stubbed tracker.
"""
try:
from performance_metrics import RobotContextTracker

return RobotContextTracker
except ImportError:
return StubbedTracker


package_to_use = _handle_package_import()
_robot_context_tracker: SupportsTracking | None = None


class StubbedTracker(SupportsTracking):
"""A stubbed tracker that does nothing."""

Expand All @@ -58,6 +41,23 @@ def store(self) -> None:
pass


def _handle_package_import() -> Type[SupportsTracking]:
"""Handle the import of the performance_metrics package.
If the package is not available, return a stubbed tracker.
"""
try:
from performance_metrics import RobotContextTracker

return RobotContextTracker
except ImportError:
return StubbedTracker


package_to_use = _handle_package_import()
_robot_context_tracker: SupportsTracking | None = None


def _get_robot_context_tracker() -> SupportsTracking:
"""Singleton for the robot context tracker."""
global _robot_context_tracker
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Performance metrics."""
Empty file.
6 changes: 6 additions & 0 deletions shared-data/python/tests/performance/test_module_builds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from pathlib import Path
from opentrons_shared_data.performance.dev_types import RobotContextState


def test_metrics_metadata(tmp_path: Path) -> None:
RobotContextState.ANALYZING_PROTOCOL

0 comments on commit ed217ba

Please sign in to comment.