-
Notifications
You must be signed in to change notification settings - Fork 178
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
feat(shared-data, api): return latest pipette version from pipetteName #15002
Changes from 7 commits
20a2066
cf6ea64
69a1b0c
6bd7761
7101eb0
fd1f11e
5cb78ef
6f7f861
048f911
7b522d5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,6 +1,9 @@ | ||||||
import os | ||||||
import re | ||||||
from typing import List, Optional, Union, cast | ||||||
from typing import List, Optional, Union, cast, Literal | ||||||
from opentrons_shared_data import get_shared_data_root | ||||||
from .dev_types import PipetteModel, PipetteName | ||||||
|
||||||
from .types import ( | ||||||
PipetteChannelType, | ||||||
PipetteModelType, | ||||||
|
@@ -106,26 +109,85 @@ | |||||
return PipetteVersionType(major, minor) | ||||||
|
||||||
|
||||||
def get_channel_from_pipette_name(pipette_name_list: List[str]) -> str: | ||||||
if "single" in pipette_name_list: | ||||||
return "single_channel" | ||||||
elif "96" in pipette_name_list: | ||||||
return "ninety_six_channel" | ||||||
else: | ||||||
return "eight_channel" | ||||||
|
||||||
|
||||||
def get_major_version_from_pipette_name( | ||||||
pipette_name_list: List[str], | ||||||
) -> Literal[1, 2, 3]: | ||||||
# special-casing for 96-channel to return version 3 | ||||||
if ( | ||||||
"flex" in pipette_name_list | ||||||
or "gen3" in pipette_name_list | ||||||
or "96" in pipette_name_list | ||||||
): | ||||||
return 3 | ||||||
elif "gen2" in pipette_name_list: | ||||||
return 2 | ||||||
else: | ||||||
return 1 | ||||||
|
||||||
|
||||||
def version_from_generation(pipette_name_list: List[str]) -> PipetteVersionType: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's drop an
|
||||||
"""Convert a string generation name to a py:obj:PipetteVersionType. | ||||||
"""Convert pipetteName to a py:obj:PipetteVersionType | ||||||
|
||||||
Pipette generations are strings in the format of "gen1" or "gen2", and | ||||||
usually associated withe :py:data:PipetteName. | ||||||
Given the pipette_name_list, cycle through each definition file path | ||||||
and find the latest version (major and minor version combined) that | ||||||
exists and return that version. | ||||||
|
||||||
Args: | ||||||
pipette_name_list (List[str]): A list of strings from the separated by `_` | ||||||
py:data:PipetteName. | ||||||
pipette_name_list (List[str]): A list of strings from the separated | ||||||
by `_` py:data:PipetteName. | ||||||
|
||||||
Returns: | ||||||
PipetteVersionType: A pipette version object. | ||||||
|
||||||
""" | ||||||
if "flex" in pipette_name_list or "gen3" in pipette_name_list: | ||||||
return PipetteVersionType(3, 0) | ||||||
elif "gen2" in pipette_name_list: | ||||||
return PipetteVersionType(2, 0) | ||||||
else: | ||||||
return PipetteVersionType(1, 0) | ||||||
major_version_from_pipette_name = get_major_version_from_pipette_name( | ||||||
pipette_name_list | ||||||
) | ||||||
model_from_pipette_name = pipette_name_list[0] | ||||||
channel_from_pipette_name = get_channel_from_pipette_name(pipette_name_list) | ||||||
|
||||||
paths_to_validate = ( | ||||||
get_shared_data_root() / "pipette" / "definitions" / "2" / "general" | ||||||
) | ||||||
|
||||||
highest_minor_version: Literal[0, 1, 2, 3, 4, 5, 6] = 0 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we'd have to update this whenever we add a new minor version, right? can we weaken its type to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, so the return type of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nevermind, this is giving me a hard time updating because all the other utils in the file use
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, a followup is fine i suppose. could we maybe have this be |
||||||
|
||||||
for channel_dir in os.listdir(paths_to_validate): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The outer two
|
||||||
if channel_dir != channel_from_pipette_name: | ||||||
continue | ||||||
|
||||||
for model_dir in os.listdir(paths_to_validate / channel_dir): | ||||||
if model_dir != model_from_pipette_name: | ||||||
continue | ||||||
|
||||||
for version_file in os.listdir(paths_to_validate / channel_dir / model_dir): | ||||||
version_list = version_file.split(".json")[0].split("_") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
(as long as we're using e.g. |
||||||
major_version = version_list[0] | ||||||
minor_version = version_list[1] | ||||||
|
||||||
# Check if the major version matches the expected major version | ||||||
if major_version == str(major_version_from_pipette_name): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe invert logic and continue to save some indentation, i.e.
|
||||||
minor_version_int = int(minor_version) | ||||||
minor_version_lit: PipetteModelMinorVersionType = cast( | ||||||
PipetteModelMinorVersionType, minor_version_int | ||||||
) | ||||||
|
||||||
# Update the highest minor version if this version is higher | ||||||
if highest_minor_version < minor_version_lit: | ||||||
highest_minor_version = minor_version_lit | ||||||
|
||||||
if highest_minor_version == 0: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i don't think we need this, right? |
||||||
return PipetteVersionType(major_version_from_pipette_name, 0) | ||||||
|
||||||
return PipetteVersionType(major_version_from_pipette_name, highest_minor_version) | ||||||
|
||||||
|
||||||
def generation_from_string(pipette_name_list: List[str]) -> PipetteGenerationType: | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i updated these to match the
uiMaxFlowRate
- see #14859 for more details