Skip to content

Commit 325a8db

Browse files
committed
renamed task_fields to get_fields
1 parent 7602066 commit 325a8db

23 files changed

+118
-120
lines changed

docs/source/tutorial/5-shell.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@
162162
"metadata": {},
163163
"outputs": [],
164164
"source": [
165-
"from pydra.utils import task_fields\n",
165+
"from pydra.utils import get_fields\n",
166166
"\n",
167167
"Cp = shell.define(\n",
168168
" \"cp <in_fs_objects:fs-object+> <out|out_dir:directory> \"\n",
@@ -172,7 +172,7 @@
172172
" \"--tuple-arg <tuple_arg:int,str=(1,'bar')> \"\n",
173173
")\n",
174174
"\n",
175-
"print(f\"'--int-arg' default: {task_fields(Cp).int_arg.default}\")"
175+
"print(f\"'--int-arg' default: {get_fields(Cp).int_arg.default}\")"
176176
]
177177
},
178178
{

docs/source/tutorial/7-canonical-form.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@
340340
"source": [
341341
"from pathlib import Path\n",
342342
"import tempfile\n",
343-
"from pydra.utils import task_as_dict\n",
343+
"from pydra.utils import asdict\n",
344344
"\n",
345345
"tmp_dir = Path(tempfile.mkdtemp())\n",
346346
"\n",
@@ -350,7 +350,7 @@
350350
"cp_file_with_size = ReloadedCpFileWithSize(in_file=a_file)\n",
351351
"outputs = cp_file_with_size(cache_root=tmp_dir / \"cache\")\n",
352352
"\n",
353-
"pprint(task_as_dict(outputs))"
353+
"pprint(asdict(outputs))"
354354
]
355355
}
356356
],

pydra/compose/base/field.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from fileformats.core import to_mime
77
from fileformats.generic import File, FileSet
88
from pydra.utils.typing import TypeParser, is_optional, is_type, is_union
9-
from pydra.utils.general import task_fields, wrap_text
9+
from pydra.utils.general import get_fields, wrap_text
1010
import attrs
1111

1212
if ty.TYPE_CHECKING:
@@ -66,7 +66,7 @@ class Requirement:
6666
def satisfied(self, inputs: "Task") -> bool:
6767
"""Check if the requirement is satisfied by the inputs"""
6868
value = getattr(inputs, self.name)
69-
field = {f.name: f for f in task_fields(inputs)}[self.name]
69+
field = {f.name: f for f in get_fields(inputs)}[self.name]
7070
if value is None or field.type is bool and value is False:
7171
return False
7272
if self.allowed_values is None:

pydra/compose/base/helpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import re
55
from copy import copy
66
from pydra.utils.typing import is_type, is_optional
7-
from pydra.utils.general import task_fields
7+
from pydra.utils.general import get_fields
88
from .field import Field, Arg, Out, NO_DEFAULT
99

1010

@@ -418,7 +418,7 @@ def extract_fields(klass, field_type, auto_attribs, helps) -> dict[str, Field]:
418418
"""Get the fields from a class"""
419419
fields_dict = {}
420420
# Get fields defined in base classes if present
421-
for field in task_fields(klass):
421+
for field in get_fields(klass):
422422
if field.name not in skip_fields:
423423
fields_dict[field.name] = field
424424
type_hints = ty.get_type_hints(klass)

pydra/compose/base/task.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from typing import Self
66
import attrs.validators
77
from pydra.utils.typing import is_optional, is_fileset_or_union
8-
from pydra.utils.general import task_fields
8+
from pydra.utils.general import get_fields
99
from pydra.utils.typing import StateArray, is_lazy
1010
from pydra.utils.hash import hash_function
1111
import os
@@ -67,7 +67,7 @@ def _from_job(cls, job: "Job[TaskType]") -> Self:
6767
The outputs of the job
6868
"""
6969
defaults = {}
70-
for output in task_fields(cls):
70+
for output in get_fields(cls):
7171
if output.mandatory:
7272
default = attrs.NOTHING
7373
elif isinstance(output.default, attrs.Factory):
@@ -116,18 +116,18 @@ def __getitem__(self, name_or_index: str | int) -> ty.Any:
116116
def __eq__(self, other: ty.Any) -> bool:
117117
"""Check if two tasks are equal"""
118118
values = attrs.asdict(self)
119-
fields = task_fields(self)
119+
fields = get_fields(self)
120120
try:
121121
other_values = attrs.asdict(other)
122122
except AttributeError:
123123
return False
124124
try:
125-
other_fields = task_fields(other)
125+
other_fields = get_fields(other)
126126
except AttributeError:
127127
return False
128128
if fields != other_fields:
129129
return False
130-
for field in task_fields(self):
130+
for field in get_fields(self):
131131
if field.hash_eq:
132132
values[field.name] = hash_function(values[field.name])
133133
other_values[field.name] = hash_function(other_values[field.name])
@@ -137,7 +137,7 @@ def __repr__(self) -> str:
137137
"""A string representation of the task"""
138138
fields_str = ", ".join(
139139
f"{f.name}={getattr(self, f.name)!r}"
140-
for f in task_fields(self)
140+
for f in get_fields(self)
141141
if getattr(self, f.name) != f.default
142142
)
143143
return f"{self.__class__.__name__}({fields_str})"
@@ -407,7 +407,7 @@ def __repr__(self) -> str:
407407
"""A string representation of the task"""
408408
fields_str = ", ".join(
409409
f"{f.name}={getattr(self, f.name)!r}"
410-
for f in task_fields(self)
410+
for f in get_fields(self)
411411
if getattr(self, f.name) != f.default
412412
)
413413
return f"{self.__class__.__name__}({fields_str})"
@@ -416,7 +416,7 @@ def __iter__(self) -> ty.Generator[str, None, None]:
416416
"""Iterate through all the names in the task"""
417417
return (
418418
f.name
419-
for f in task_fields(self)
419+
for f in get_fields(self)
420420
if not (f.name.startswith("_") or f.name in self.RESERVED_FIELD_NAMES)
421421
)
422422

@@ -431,7 +431,7 @@ def __eq__(self, other: ty.Any) -> bool:
431431
return False
432432
if set(values) != set(other_values):
433433
return False # Return if attribute keys don't match
434-
for field in task_fields(self):
434+
for field in get_fields(self):
435435
if field.hash_eq:
436436
values[field.name] = hash_function(values[field.name])
437437
other_values[field.name] = hash_function(other_values[field.name])
@@ -486,7 +486,7 @@ def _hash_changes(self):
486486
def _compute_hashes(self) -> ty.Tuple[bytes, ty.Dict[str, bytes]]:
487487
"""Compute a basic hash for any given set of fields."""
488488
inp_dict = {}
489-
for field in task_fields(self):
489+
for field in get_fields(self):
490490
if isinstance(field, Out):
491491
continue # Skip output fields
492492
# removing values that are not set from hash calculation
@@ -508,7 +508,7 @@ def _rule_violations(self) -> list[str]:
508508

509509
field: Arg
510510
errors = []
511-
for field in task_fields(self):
511+
for field in get_fields(self):
512512
value = self[field.name]
513513

514514
if is_lazy(value):
@@ -625,7 +625,7 @@ def _check_resolved(self):
625625
@register_serializer
626626
def bytes_repr_task(obj: Task, cache: Cache) -> ty.Iterator[bytes]:
627627
yield f"task[{obj._task_type()}]:(".encode()
628-
for field in task_fields(obj):
628+
for field in get_fields(obj):
629629
yield f"{field.name}=".encode()
630630
yield hash_single(getattr(obj, field.name), cache)
631631
yield b","

pydra/compose/python.py

Lines changed: 3 additions & 3 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, task_as_dict
5+
from pydra.utils.general import get_fields, asdict
66
from pydra.compose import base
77
from pydra.compose.base import (
88
ensure_field_objects,
@@ -226,12 +226,12 @@ class PythonTask(base.Task[PythonOutputsType]):
226226

227227
def _run(self, job: "Job[PythonTask]", rerun: bool = True) -> None:
228228
# Prepare the inputs to the function
229-
inputs = task_as_dict(self)
229+
inputs = asdict(self)
230230
del inputs["function"]
231231
# Run the actual function
232232
returned = self.function(**inputs)
233233
# Collect the outputs and save them into the job.return_values dictionary
234-
return_names = [f.name for f in task_fields(self.Outputs)]
234+
return_names = [f.name for f in get_fields(self.Outputs)]
235235
if returned is None:
236236
job.return_values = {nm: None for nm in return_names}
237237
elif not return_names:

pydra/compose/shell/task.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from fileformats.generic import FileSet, File
1212
from pydra.utils.general import (
1313
attrs_values,
14-
task_fields,
14+
get_fields,
1515
ensure_list,
1616
position_sort,
1717
)
@@ -80,7 +80,7 @@ def _from_job(cls, job: "Job[Task]") -> ty.Self:
8080
"""
8181
outputs = super()._from_job(job)
8282
fld: field.out
83-
for fld in task_fields(cls):
83+
for fld in get_fields(cls):
8484
if fld.name in ["return_code", "stdout", "stderr"]:
8585
resolved_value = job.return_values[fld.name]
8686
# Get the corresponding value from the inputs if it exists, which will be
@@ -281,7 +281,7 @@ def _command_args(self, values: dict[str, ty.Any]) -> list[str]:
281281
self._check_rules()
282282
# Drop none/empty values and optional path fields that are set to false
283283
values = copy(values) # Create a copy so we can drop items from the dictionary
284-
for fld in task_fields(self):
284+
for fld in get_fields(self):
285285
fld_value = values[fld.name]
286286
if fld_value is None or (is_multi_input(fld.type) and fld_value == []):
287287
del values[fld.name]
@@ -295,7 +295,7 @@ def _command_args(self, values: dict[str, ty.Any]) -> list[str]:
295295
self._command_shelltask_executable(fld, self.executable),
296296
] # list for (position, command arg)
297297
positions_provided = [0]
298-
fields = {f.name: f for f in task_fields(self)}
298+
fields = {f.name: f for f in get_fields(self)}
299299
for field_name in values:
300300
pos_val = self._command_pos_args(
301301
fld=fields[field_name],
@@ -449,7 +449,7 @@ def _rule_violations(self) -> list[str]:
449449
errors = super()._rule_violations()
450450
# if there is a value that has to be updated (e.g. single value from a list)
451451
# getting all fields that should be formatted, i.e. {field_name}, ...
452-
fields = task_fields(self)
452+
fields = get_fields(self)
453453
available_template_names = [f.name for f in fields] + ["field", "inputs"]
454454
for fld in fields:
455455
if fld.argstr:

pydra/compose/shell/templating.py

Lines changed: 2 additions & 2 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 attrs_values, get_fields
99
from pydra.utils.typing import is_lazy
1010
from . import field
1111

@@ -32,7 +32,7 @@ def template_update(
3232
# Collect templated inputs for which all requirements are satisfied.
3333
fields_templ = [
3434
fld
35-
for fld in task_fields(task)
35+
for fld in get_fields(task)
3636
if isinstance(fld, field.outarg)
3737
and fld.path_template
3838
and getattr(task, fld.name)

pydra/compose/shell/tests/test_shell_fields.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import pytest
66
import cloudpickle as cp
77
from pydra.compose import shell
8-
from pydra.utils.general import task_fields, task_help, wrap_text
8+
from pydra.utils.general import get_fields, task_help, wrap_text
99
from pydra.compose.shell.builder import _InputPassThrough
1010
from fileformats.generic import File, Directory, FsObject
1111
from fileformats import text, image
@@ -1032,7 +1032,7 @@ def list_entries(stdout):
10321032

10331033

10341034
def sorted_fields(interface):
1035-
fields = task_fields(interface)
1035+
fields = get_fields(interface)
10361036
length = len(fields) - 1
10371037

10381038
def pos_key(out: shell.out) -> int:

pydra/compose/tests/test_python_equivalence.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
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 get_fields, attrs_values
77

88

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

1212

1313
def non_func_values(defn: python.Task) -> dict:
@@ -79,16 +79,16 @@ def Indirect(a):
7979
assert non_func_fields(Direct) == non_func_fields(Partial)
8080
assert non_func_fields(Direct) == non_func_fields(Indirect)
8181

82-
assert task_fields(Direct.Outputs) == task_fields(Partial.Outputs)
83-
assert task_fields(Direct.Outputs) == task_fields(Indirect.Outputs)
82+
assert get_fields(Direct.Outputs) == get_fields(Partial.Outputs)
83+
assert get_fields(Direct.Outputs) == get_fields(Indirect.Outputs)
8484

8585
# Run functions to ensure behavior is unaffected
8686
a = random.randint(0, (1 << 32) - 3)
8787
assert non_func_values(Direct(a=a)) == non_func_values(Partial(a=a))
8888
assert non_func_values(Direct(a=a)) == non_func_values(Indirect(a=a))
8989

9090
# checking if the annotation is properly converted to output_spec if used in task
91-
assert task_fields(Direct.Outputs).out == python.out(name="out", type=int)
91+
assert get_fields(Direct.Outputs).out == python.out(name="out", type=int)
9292

9393

9494
def test_annotation_equivalence_2():
@@ -117,7 +117,7 @@ def Indirect(a) -> tuple[int, float]:
117117
assert hashes(Direct(a=a)) == hashes(Partial(a=a)) == hashes(Indirect(a=a))
118118

119119
# checking if the annotation is properly converted to output_spec if used in task
120-
assert list(task_fields(Direct.Outputs)) == [
120+
assert list(get_fields(Direct.Outputs)) == [
121121
python.out(name="out1", type=int),
122122
python.out(name="out2", type=float),
123123
]
@@ -149,7 +149,7 @@ def Indirect(a):
149149
assert hashes(Direct(a=a)) == hashes(Partial(a=a)) == hashes(Indirect(a=a))
150150

151151
# checking if the annotation is properly converted to output_spec if used in task
152-
assert task_fields(Direct.Outputs).out1 == python.out(name="out1", type=int)
152+
assert get_fields(Direct.Outputs).out1 == python.out(name="out1", type=int)
153153

154154

155155
def test_annotation_equivalence_4():
@@ -169,22 +169,22 @@ def Indirect(a):
169169

170170
# checking if the annotations are equivalent
171171
assert (
172-
task_fields(Direct.Outputs)
173-
== task_fields(Partial.Outputs)
174-
== task_fields(Indirect.Outputs)
172+
get_fields(Direct.Outputs)
173+
== get_fields(Partial.Outputs)
174+
== get_fields(Indirect.Outputs)
175175
)
176176
assert (
177-
task_fields(Direct.Outputs)
178-
== task_fields(Partial.Outputs)
179-
== task_fields(Indirect.Outputs)
177+
get_fields(Direct.Outputs)
178+
== get_fields(Partial.Outputs)
179+
== get_fields(Indirect.Outputs)
180180
)
181181

182182
# Run functions to ensure behavior is unaffected
183183
a = random.randint(0, (1 << 32) - 3)
184184
assert hashes(Direct(a=a)) == hashes(Partial(a=a)) == hashes(Indirect(a=a))
185185

186186
# checking if the annotation is properly converted to output_spec if used in task
187-
assert list(task_fields(Direct.Outputs)) == [
187+
assert list(get_fields(Direct.Outputs)) == [
188188
python.out(name="sum", type=int),
189189
python.out(name="sub", type=int),
190190
]

0 commit comments

Comments
 (0)