Skip to content

Commit

Permalink
fix(protocols): re-add get_all_labware_definitions (#17077)
Browse files Browse the repository at this point in the history
  • Loading branch information
caila-marashaj authored Dec 10, 2024
1 parent 906d841 commit 059380b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
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

0 comments on commit 059380b

Please sign in to comment.