Skip to content

Commit

Permalink
feat: Updated docstrings, tests and cwl structure.
Browse files Browse the repository at this point in the history
  • Loading branch information
KamenDimitrov97 committed Jul 25, 2024
1 parent e94d1a2 commit 6b181cb
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
5 changes: 2 additions & 3 deletions src/dewret/renderers/cwl.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,6 @@ def to_cwl_type(typ: type) -> str | dict[str, Any] | list[str]:
CWL specification type name, or a list
if a union.
"""
if isinstance(typ, UnionType):
return [to_cwl_type(item) for item in get_args(typ)]

if typ == int:
return "int"
elif typ == bool:
Expand All @@ -220,6 +217,8 @@ def to_cwl_type(typ: type) -> str | dict[str, Any] | list[str]:
return "bytes"
elif configuration("allow_complex_types"):
return typ if isinstance(typ, str) else typ.__name__
elif isinstance(typ, UnionType):
return [to_cwl_type(item) for item in get_args(typ)]
elif isinstance(typ, Iterable):
try:
basic_types = get_args(typ)
Expand Down
13 changes: 7 additions & 6 deletions src/dewret/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,14 +743,15 @@ def __eq__(self, other: object) -> bool:
)

def set_workflow(self, workflow: Workflow, with_arguments: bool = True) -> None:
"""Move the step reference to another workflow.
"""Move the step reference to a different workflow.
Primarily intended to be called by its step, as a cascade.
It will attempt to update its arguments, similarly.
This method is primarily intended to be called by a step, allowing it to
switch to a new workflow. It also updates the workflow reference for any
arguments that are steps themselves, if specified.
Args:
workflow: the new target workflow.
with_arguments: set workflows for the arguments..
workflow: The new target workflow to which the step should be moved.
with_arguments: If True, also update the workflow reference for the step's arguments.
"""
self.__workflow__ = workflow
if with_arguments:
Expand Down Expand Up @@ -1052,7 +1053,7 @@ def __repr__(self) -> str:
"""Hashable reference to the step (and field)."""
return f"{self.step.id}/{self.field}"

def __getattr__(self, attr: str) -> "StepReference"[Any]:
def __getattr__(self, attr: str) -> "StepReference[Any]":
"""Reference to a field within this result, if possible.
If the result is an attrs-class or dataclass, this will pull out an individual
Expand Down
4 changes: 2 additions & 2 deletions tests/test_cwl.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,9 +525,9 @@ def test_cwl_with_subworkflow_and_raw_params() -> None:


def test_tuple_floats() -> None:
"""Check whether we can link between multiple steps.
"""Checks whether we can return a tuple.
Produces CWL that has references between multiple steps.
Produces CWL that has a tuple of 2 values of type float.
"""
result = tuple_float_return()
workflow = construct(result, simplify_ids=True)
Expand Down
18 changes: 9 additions & 9 deletions tests/test_multiresult_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ def combine(left: int, right: float) -> float:

@task()
def list_cast(iterable: Iterable[float]) -> list[float]:
"""Sum two values."""
"""Converts an iterable structure with float elements into a list of floats."""
return list(iterable)


@task()
def pair(left: int, right: float) -> tuple[float, float]:
"""Sum two values."""
def pair(left: int, right: float) -> tuple[int, float]:
"""Pairs two values."""
return (left, right)


Expand All @@ -51,22 +51,22 @@ def algorithm() -> float:


@nested_task()
def algorithm_with_pair() -> tuple[float, float]:
"""Sum two split values."""
def algorithm_with_pair() -> tuple[int, float]:
"""Pairs two split dataclass values."""
return pair(left=split_into_dataclass().first, right=split_into_dataclass().second)


@nested_task()
def algorithm_with_dataclasses() -> float:
"""Sum two split values."""
"""Sums two split dataclass values."""
return combine(
left=split_into_dataclass().first, right=split_into_dataclass().second
)


@task()
def split() -> SplitResult:
"""Create a result with two fields."""
"""Create a split result with two fields."""
return SplitResult(first=1, second=2)


Expand Down Expand Up @@ -171,7 +171,7 @@ def test_field_of_nested_task_into_dataclasses() -> None:


def test_complex_field_of_nested_task() -> None:
"""Tests whether a task can insert result fields into other steps."""
"""Tests whether a task can sum complex structures."""
workflow = construct(algorithm(), simplify_ids=True)
rendered = render(workflow)

Expand Down Expand Up @@ -258,7 +258,7 @@ def test_pair_can_be_returned_from_step() -> None:
outputSource: pair-1/out
type:
items:
- type: float
- type: int
- type: float
type: array
steps:
Expand Down

0 comments on commit 6b181cb

Please sign in to comment.