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

refactor(api, robot-server): move feature flag file access outside of hardware_control #13963

Merged
merged 10 commits into from
Dec 1, 2023

Conversation

fsinapi
Copy link
Contributor

@fsinapi fsinapi commented Nov 9, 2023

Overview

As a part of the long-term goal of the hardware controller process split, we need to address simultaneous access & modification of the feature flags file on a robot. This PR takes out any parts of the hardware_control submodule in the opentrons package that directly access the feature flags file, replacing them with a dataclass that just gets populated by the caller of the factory functions. This gets used to dictate whether the pipette handlers use the new or old aspiration functions, as well as a few Flex-specific hardware functions.

Test Plan

To verify that the settings are being updated in the API correctly, I pushed on a robot, used HTTP to change the advanced setting requiring the estop, and disconnected the estop to ensure that no error popped up.

CI tests should cover that the settings are still being set/read the right way.

Ran the REPL on a robot and changed some settings in feature_flags.json to ensure they are reflected in the constructed API.

Changelog

  • Updated OT2 and Flex hardware feature flags to be passed into the API instance on init
  • Modified OT2 and Flex pipette handler to not read from feature flag file
  • Added function to API protocol to allow reconfiguration of feature flags

Review requests

I don't like this interface but I don't see an elegant alternative. Injecting into the robot configs seems inappropriate imo. Any strong opinion on an alternative approach is appreciated.

Risk assessment

Medium, mostly if I missed any hardware API initializers somewhere in the repo.

@fsinapi fsinapi requested review from sfoster1 and a team November 9, 2023 21:31
@fsinapi fsinapi self-assigned this Nov 9, 2023
@fsinapi fsinapi requested a review from a team as a code owner November 9, 2023 21:31
Copy link

codecov bot commented Nov 9, 2023

Codecov Report

Merging #13963 (8aff794) into edge (9dd2d1f) will decrease coverage by 0.11%.
Report is 1 commits behind head on edge.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             edge   #13963      +/-   ##
==========================================
- Coverage   70.59%   70.49%   -0.11%     
==========================================
  Files        2506     2507       +1     
  Lines       71081    71083       +2     
  Branches     8907     8916       +9     
==========================================
- Hits        50179    50108      -71     
- Misses      18723    18790      +67     
- Partials     2179     2185       +6     
Flag Coverage Δ
app 67.75% <ø> (ø)
components 62.58% <ø> (ø)
g-code-testing 96.44% <100.00%> (+<0.01%) ⬆️
hardware-testing ∅ <ø> (∅)
labware-library 51.50% <ø> (ø)
notify-server 89.13% <ø> (ø)
protocol-designer 45.02% <ø> (ø)
react-api-client 65.73% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
api/src/opentrons/__init__.py 51.16% <ø> (ø)
api/src/opentrons/execute.py 54.23% <ø> (ø)
api/src/opentrons/hardware_control/__main__.py 0.00% <ø> (ø)
api/src/opentrons/hardware_control/api.py 82.42% <ø> (ø)
...entrons/hardware_control/backends/ot3controller.py 67.85% <ø> (ø)
...pentrons/hardware_control/backends/ot3simulator.py 86.44% <ø> (ø)
api/src/opentrons/hardware_control/ot3api.py 79.58% <ø> (+0.17%) ⬆️
...entrons/hardware_control/protocols/configurable.py 68.75% <ø> (ø)
api/src/opentrons/hardware_control/scripts/repl.py 0.00% <ø> (ø)
.../src/opentrons/hardware_control/simulator_setup.py 82.22% <ø> (ø)
... and 5 more

... and 38 files with indirect coverage changes

@fsinapi fsinapi marked this pull request as draft November 9, 2023 21:48
@fsinapi fsinapi marked this pull request as ready for review November 13, 2023 15:31
@fsinapi fsinapi requested a review from a team as a code owner November 13, 2023 15:31
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.

I think unfortunately we need to not build function argument defaults like this but other than that looks great!

@@ -111,6 +112,7 @@ def __init__(
backend: Union[Controller, Simulator],
loop: asyncio.AbstractEventLoop,
config: RobotConfig,
feature_flags: HardwareFeatureFlags = HardwareFeatureFlags(),
Copy link
Member

Choose a reason for hiding this comment

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

this probably wants to be Optional[HardwareFeatureFlags] = None because this code will create one default HardwareFeatureFlags() at function parse time that will be reused lol

@@ -170,6 +173,7 @@ async def build_hardware_controller(
port: Optional[str] = None,
loop: Optional[asyncio.AbstractEventLoop] = None,
firmware: Optional[Tuple[pathlib.Path, str]] = None,
feature_flags: HardwareFeatureFlags = HardwareFeatureFlags(),
Copy link
Member

Choose a reason for hiding this comment

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

ditto here

@@ -249,6 +258,7 @@ async def build_hardware_simulator(
config: Optional[Union[RobotConfig, OT3Config]] = None,
loop: Optional[asyncio.AbstractEventLoop] = None,
strict_attached_instruments: bool = True,
feature_flags: HardwareFeatureFlags = HardwareFeatureFlags(),
Copy link
Member

Choose a reason for hiding this comment

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

ditto here

config: OT3Config,
use_usb_bus: bool = False,
check_updates: bool = True,
feature_flags: HardwareFeatureFlags = HardwareFeatureFlags(),
Copy link
Member

Choose a reason for hiding this comment

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

ditto here

@@ -274,6 +283,7 @@ def __init__(
usb_driver: Optional[SerialUsbDriver] = None,
eeprom_driver: Optional[EEPROMDriver] = None,
check_updates: bool = True,
feature_flags: HardwareFeatureFlags = HardwareFeatureFlags(),
Copy link
Member

Choose a reason for hiding this comment

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

ditto here

@hardware_feature_flags.setter
def hardware_feature_flags(self, feature_flags: HardwareFeatureFlags) -> None:
self._feature_flags = feature_flags
if isinstance(self._backend, OT3Controller):
Copy link
Member

Choose a reason for hiding this comment

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

let's just do it for the simulator too

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.

Looks good though I feel like we might want a note about the no-arguments constructor wanting to be where default-true arguments are or something

@fsinapi fsinapi merged commit fda0f5c into edge Dec 1, 2023
45 of 46 checks passed
@fsinapi fsinapi deleted the RET-1382-Refactor-feature-flags-out-of-hardware-code branch December 1, 2023 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants