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

fix(protocols): re-add get_all_labware_definitions #17077

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions api/src/opentrons/protocols/api_support/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,3 +391,13 @@ def _check_version_wrapper(*args: Any, **kwargs: Any) -> Any:
return cast(FuncT, _check_version_wrapper)

return _set_version


class ModifiedList(list[str]):
def __contains__(self, item: object) -> bool:
if not isinstance(item, str):
return False
for name in self:
if name == item.replace("-", "_").lower():
return True
return False
25 changes: 24 additions & 1 deletion api/src/opentrons/protocols/labware.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import logging
import json
import os

from pathlib import Path
from typing import Any, AnyStr, Dict, Optional, Union
from typing import Any, AnyStr, Dict, Optional, Union, List

import jsonschema # type: ignore

from opentrons_shared_data import load_shared_data, get_shared_data_root
from opentrons.protocols.api_support.util import ModifiedList
from opentrons.protocols.api_support.constants import (
OPENTRONS_NAMESPACE,
CUSTOM_NAMESPACE,
Expand Down Expand Up @@ -61,6 +63,27 @@ def get_labware_definition(
return _get_standard_labware_definition(load_name, namespace, version)


def get_all_labware_definitions() -> List[str]:
"""
Return a list of standard and custom labware definitions with load_name +
name_space + version existing on the robot
"""
labware_list = ModifiedList()

def _check_for_subdirectories(path: Union[str, Path, os.DirEntry[str]]) -> None:
with os.scandir(path) as top_path:
for sub_dir in top_path:
if sub_dir.is_dir():
labware_list.append(sub_dir.name)

# check for standard labware
_check_for_subdirectories(get_shared_data_root() / STANDARD_DEFS_PATH)
# check for custom labware
for namespace in os.scandir(USER_DEFS_PATH):
_check_for_subdirectories(namespace)
return labware_list


def save_definition(
labware_def: LabwareDefinition, force: bool = False, location: Optional[Path] = None
) -> None:
Expand Down
Loading