Skip to content

Commit

Permalink
Add DatasetCollectionElementWrapper type alias
Browse files Browse the repository at this point in the history
  • Loading branch information
nsoranzo committed Mar 6, 2024
1 parent 05b467d commit fac8eed
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/galaxy/tools/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
)

from packaging.version import Version
from typing_extensions import TypeAlias

from galaxy.model import (
DatasetCollection,
Expand Down Expand Up @@ -605,6 +606,9 @@ def __bool__(self) -> bool:
__nonzero__ = __bool__


DatasetCollectionElementWrapper: TypeAlias = Union["DatasetCollectionWrapper", DatasetFilenameWrapper]


class DatasetCollectionWrapper(ToolParameterValueWrapper, HasDatasets):
name: Optional[str]
collection: DatasetCollection
Expand Down Expand Up @@ -642,15 +646,15 @@ def __init__(
self.collection = collection

elements = collection.elements
element_instances: Dict[str, Union[DatasetCollectionWrapper, DatasetFilenameWrapper]] = {}
element_instances: Dict[str, DatasetCollectionElementWrapper] = {}

element_instance_list: List[Union[DatasetCollectionWrapper, DatasetFilenameWrapper]] = []
element_instance_list: List[DatasetCollectionElementWrapper] = []
for dataset_collection_element in elements:
element_object = dataset_collection_element.element_object
element_identifier = dataset_collection_element.element_identifier

if dataset_collection_element.is_collection:
element_wrapper: Union[DatasetCollectionWrapper, DatasetFilenameWrapper] = DatasetCollectionWrapper(
element_wrapper: DatasetCollectionElementWrapper = DatasetCollectionWrapper(
job_working_directory, dataset_collection_element, **kwargs
)
else:
Expand Down Expand Up @@ -757,15 +761,15 @@ def serialize(
def is_input_supplied(self) -> bool:
return self.__input_supplied

def __getitem__(self, key: Union[str, int]) -> Union[None, "DatasetCollectionWrapper", DatasetFilenameWrapper]:
def __getitem__(self, key: Union[str, int]) -> Optional[DatasetCollectionElementWrapper]:
if not self.__input_supplied:
return None
if isinstance(key, int):
return self.__element_instance_list[key]
else:
return self.__element_instances[key]

def __getattr__(self, key: str) -> Union[None, "DatasetCollectionWrapper", DatasetFilenameWrapper]:
def __getattr__(self, key: str) -> Optional[DatasetCollectionElementWrapper]:
if not self.__input_supplied:
return None
try:
Expand All @@ -775,7 +779,7 @@ def __getattr__(self, key: str) -> Union[None, "DatasetCollectionWrapper", Datas

def __iter__(
self,
) -> Iterator[Union["DatasetCollectionWrapper", DatasetFilenameWrapper]]:
) -> Iterator[DatasetCollectionElementWrapper]:
if not self.__input_supplied:
return [].__iter__()
return self.__element_instance_list.__iter__()
Expand Down

0 comments on commit fac8eed

Please sign in to comment.