Skip to content

Commit d4bd405

Browse files
committed
replaced usage of attrs_values with task_dict
1 parent 89a474a commit d4bd405

File tree

16 files changed

+55
-61
lines changed

16 files changed

+55
-61
lines changed

pydra/compose/base/task.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from pydra.utils.messenger import AuditFlag, Messenger
1717
from pydra.utils.general import (
1818
attrs_fields,
19-
attrs_values,
19+
task_dict,
2020
)
2121
from pydra.utils.hash import Cache, hash_single, register_serializer
2222
from .field import Field, Arg, Out
@@ -590,7 +590,7 @@ def _check_arg_refs(
590590

591591
def _check_resolved(self):
592592
"""Checks that all the fields in the task have been resolved"""
593-
if lazy_values := [n for n, v in attrs_values(self).items() if is_lazy(v)]:
593+
if lazy_values := [n for n, v in task_dict(self).items() if is_lazy(v)]:
594594
raise ValueError(
595595
f"Cannot execute {self} because the following fields "
596596
f"still have lazy values {lazy_values}"

pydra/compose/python.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import inspect
33
from typing import dataclass_transform
44
import attrs
5-
from pydra.utils.general import task_fields, attrs_values
5+
from pydra.utils.general import task_fields, task_dict
66
from pydra.compose import base
77
from pydra.compose.base import (
88
ensure_field_objects,
@@ -231,7 +231,7 @@ class PythonTask(base.Task[PythonOutputsType]):
231231

232232
def _run(self, job: "Job[PythonTask]", rerun: bool = True) -> None:
233233
# Prepare the inputs to the function
234-
inputs = attrs_values(self)
234+
inputs = task_dict(self)
235235
del inputs["function"]
236236
# Run the actual function
237237
returned = self.function(**inputs)

pydra/compose/shell/builder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from fileformats.core import from_mime
1414
from fileformats import generic
1515
from fileformats.core.exceptions import FormatRecognitionError
16-
from pydra.utils.general import attrs_values
16+
from pydra.utils.general import task_dict
1717
from pydra.compose.base import (
1818
Arg,
1919
Out,
@@ -375,7 +375,7 @@ def add_arg(name, field_type, kwds):
375375
kwds["type"] = fld
376376
fld = field_type(name=name, **kwds)
377377
elif not isinstance(fld, field_type): # If fld type is outarg not out
378-
fld = field_type(**attrs_values(fld))
378+
fld = field_type(**task_dict(fld))
379379
fld.name = name
380380
type_ = kwds.pop("type", fld.type)
381381
if fld.type is ty.Any:

pydra/compose/shell/task.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import attrs
1111
from fileformats.generic import FileSet, File
1212
from pydra.utils.general import (
13-
attrs_values,
13+
task_dict,
1414
task_fields,
1515
ensure_list,
1616
position_sort,
@@ -261,7 +261,7 @@ def cmdline(self) -> str:
261261
"""The equivalent command line that would be submitted if the job were run on
262262
the current working directory."""
263263
# Skip the executable, which can be a multi-part command, e.g. 'docker run'.
264-
values = attrs_values(self)
264+
values = task_dict(self)
265265
values.update(template_update(self, output_dir=Path.cwd()))
266266
cmd_args = self._command_args(values=values)
267267
cmdline = cmd_args[0]

pydra/compose/shell/templating.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from copy import copy
66
from pathlib import Path
77
from fileformats.generic import FileSet
8-
from pydra.utils.general import attrs_values, task_fields
8+
from pydra.utils.general import task_dict, task_fields
99
from pydra.utils.typing import is_lazy
1010
from . import field
1111

@@ -25,7 +25,7 @@ def template_update(
2525
2626
"""
2727

28-
values = attrs_values(task)
28+
values = task_dict(task)
2929
if map_copyfiles is not None:
3030
values.update(map_copyfiles)
3131

@@ -69,7 +69,7 @@ def template_update_single(
6969
from pydra.utils.typing import TypeParser, OUTPUT_TEMPLATE_TYPES # noqa
7070

7171
if values is None:
72-
values = attrs_values(task)
72+
values = task_dict(task)
7373

7474
if spec_type == "input":
7575
field_value = values[fld.name]

pydra/compose/tests/test_python_equivalence.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
import typing as ty
44
from pydra.compose.base import Field
55
from pydra.compose import python
6-
from pydra.utils.general import task_fields, attrs_values
6+
from pydra.utils.general import task_fields, task_dict
77

88

99
def non_func_fields(defn: python.Task) -> list[Field]:
1010
return [f for f in task_fields(defn) if f.name != "function"]
1111

1212

1313
def non_func_values(defn: python.Task) -> dict:
14-
return {n: v for n, v in attrs_values(defn).items() if n != "function"}
14+
return {n: v for n, v in task_dict(defn).items() if n != "function"}
1515

1616

1717
def hashes(defn: python.Task) -> dict[str, str]:

pydra/compose/workflow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
check_explicit_fields_are_none,
1212
extract_fields_from_class,
1313
)
14-
from pydra.utils.general import attrs_values
14+
from pydra.utils.general import task_dict
1515
from pydra.utils.typing import StateArray
1616

1717
if ty.TYPE_CHECKING:
@@ -329,7 +329,7 @@ def _from_task(cls, job: "Job[WorkflowTask]") -> ty.Self:
329329
# Retrieve values from the output fields
330330
values = {}
331331
lazy_field: LazyOutField
332-
for name, lazy_field in attrs_values(workflow.outputs).items():
332+
for name, lazy_field in task_dict(workflow.outputs).items():
333333
val_out = lazy_field._get_value(workflow=workflow, graph=exec_graph)
334334
if isinstance(val_out, StateArray):
335335
val_out = list(val_out) # implicitly combine state arrays

pydra/engine/audit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import typing as ty
55
import json
66
from pydra.utils.messenger import send_message, make_message, gen_uuid, now, AuditFlag
7-
from pydra.utils.general import attrs_values
7+
from pydra.utils.general import task_dict
88
from fileformats.core import FileSet
99
from pydra.utils.hash import hash_function
1010

@@ -108,7 +108,7 @@ def finalize_audit(self, result):
108108
)
109109
# audit resources/runtime information
110110
self.eid = f"uid:{gen_uuid()}"
111-
entity = attrs_values(result.runtime)
111+
entity = task_dict(result.runtime)
112112
entity.update(
113113
**{
114114
"@id": self.eid,

pydra/engine/job.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
record_error,
2626
)
2727
from pydra.utils.general import (
28-
attrs_values,
28+
task_dict,
2929
attrs_fields,
3030
task_fields,
3131
ensure_list,
@@ -248,7 +248,7 @@ def inputs(self) -> dict[str, ty.Any]:
248248
from pydra.utils.typing import TypeParser
249249

250250
self._inputs = {
251-
k: v for k, v in attrs_values(self.task).items() if not k.startswith("_")
251+
k: v for k, v in task_dict(self.task).items() if not k.startswith("_")
252252
}
253253
map_copyfiles = {}
254254
fld: "Arg"

pydra/engine/node.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from enum import Enum
44
import attrs
55
from pydra.engine import lazy
6-
from pydra.utils.general import attrs_values
6+
from pydra.utils.general import task_dict
77
from pydra.utils.typing import is_lazy
88
from pydra.engine.state import State, add_name_splitter, add_name_combiner
99

@@ -87,7 +87,7 @@ def inputs(self) -> Inputs:
8787

8888
@property
8989
def input_names(self) -> list[str]:
90-
return list(attrs_values(self._task).keys())
90+
return list(task_dict(self._task).keys())
9191

9292
@property
9393
def state(self):
@@ -98,7 +98,7 @@ def state(self):
9898

9999
@property
100100
def input_values(self) -> tuple[tuple[str, ty.Any]]:
101-
return tuple(attrs_values(self._task).items())
101+
return tuple(task_dict(self._task).items())
102102

103103
@property
104104
def state_values(self) -> dict[str, ty.Any]:
@@ -110,7 +110,7 @@ def state_values(self) -> dict[str, ty.Any]:
110110
dict[str, Any]
111111
The values of the task
112112
"""
113-
return {f"{self.name}.{n}": v for n, v in attrs_values(self._task).items()}
113+
return {f"{self.name}.{n}": v for n, v in task_dict(self._task).items()}
114114

115115
@property
116116
def lzout(self) -> OutputType:
@@ -129,7 +129,7 @@ def lzout(self) -> OutputType:
129129
outputs = self.inputs.Outputs(**lazy_fields)
130130

131131
outpt: lazy.LazyOutField
132-
for outpt in attrs_values(outputs).values():
132+
for outpt in task_dict(outputs).values():
133133
# Assign the current node to the lazy fields so they can access the state
134134
outpt._node = self
135135
# If the node has a non-empty state, wrap the type of the lazy field in

0 commit comments

Comments
 (0)