Skip to content

Commit a490a01

Browse files
committed
replaced serialize_task_class and unserialize_task_class with unstructure and structure, respectively, to match terminology used by attrs
1 parent 55bab79 commit a490a01

File tree

4 files changed

+29
-29
lines changed

4 files changed

+29
-29
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@
246246
"\n",
247247
"As well as the dataclass-like canonical form, it is also possible to represent all tasks\n",
248248
"in a nested dictionary form, which could be written to a static file (e.g. in JSON or\n",
249-
"YAML format). The dictionary form of a class can be generated by the `pydra.utils.serialize_task_class`\n",
249+
"YAML format). The dictionary form of a class can be generated by the `pydra.utils.unstructure`\n",
250250
"function. For example, the following shell command"
251251
]
252252
},
@@ -278,9 +278,9 @@
278278
"outputs": [],
279279
"source": [
280280
"from pprint import pprint\n",
281-
"from pydra.utils import serialize_task_class\n",
281+
"from pydra.utils import unstructure\n",
282282
"\n",
283-
"my_cmd_dict = serialize_task_class(MyCmd)\n",
283+
"my_cmd_dict = unstructure(MyCmd)\n",
284284
"\n",
285285
"pprint(my_cmd_dict)"
286286
]
@@ -300,7 +300,7 @@
300300
"metadata": {},
301301
"outputs": [],
302302
"source": [
303-
"cp_with_size_dict = serialize_task_class(CpFileWithSize)\n",
303+
"cp_with_size_dict = unstructure(CpFileWithSize)\n",
304304
"\n",
305305
"pprint(cp_with_size_dict)"
306306
]
@@ -310,7 +310,7 @@
310310
"metadata": {},
311311
"source": [
312312
"To unserialize the general dictionary form back into a Task class, you can use the\n",
313-
"`pydra.utils.unserialize_task_class` method"
313+
"`pydra.utils.structure` method"
314314
]
315315
},
316316
{
@@ -319,9 +319,9 @@
319319
"metadata": {},
320320
"outputs": [],
321321
"source": [
322-
"from pydra.utils import unserialize_task_class\n",
322+
"from pydra.utils import structure\n",
323323
"\n",
324-
"ReloadedCpFileWithSize = unserialize_task_class(cp_with_size_dict)"
324+
"ReloadedCpFileWithSize = structure(cp_with_size_dict)"
325325
]
326326
},
327327
{

pydra/utils/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
show_workflow,
66
task_help,
77
print_help,
8-
serialize_task_class,
9-
unserialize_task_class,
8+
unstructure,
9+
structure,
1010
)
1111
from ._version import __version__
1212

@@ -18,6 +18,6 @@
1818
"show_workflow",
1919
"task_help",
2020
"print_help",
21-
"serialize_task_class",
22-
"unserialize_task_class",
21+
"unstructure",
22+
"structure",
2323
]

pydra/utils/general.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ def get_plugin_classes(namespace: types.ModuleType, class_name: str) -> dict[str
588588
}
589589

590590

591-
def serialize_task_class(
591+
def unstructure(
592592
task_class: "type[Task]",
593593
filter: ty.Callable[[attrs.Attribute, ty.Any], bool] | None = None,
594594
value_serializer: (
@@ -685,8 +685,8 @@ def full_val_serializer(
685685
return dct
686686

687687

688-
def unserialize_task_class(task_class_dict: dict[str, ty.Any]) -> type["Task"]:
689-
"""Unserializes a task definition from a dictionary created by `serialize_task_class`
688+
def structure(task_class_dict: dict[str, ty.Any]) -> type["Task"]:
689+
"""Unserializes a task definition from a dictionary created by `unstructure`
690690
691691
Parameters
692692
----------

pydra/utils/tests/test_general.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
from pydra.compose import python, workflow, shell
55
from fileformats.text import TextFile
66
from pydra.utils.general import (
7-
serialize_task_class,
8-
unserialize_task_class,
7+
unstructure,
8+
structure,
99
get_fields,
1010
filter_out_defaults,
1111
)
@@ -49,33 +49,33 @@ def Add(a: int, b: int | None = None, c: int | None = None) -> int:
4949
return a + (b if b is not None else c)
5050

5151

52-
def test_python_serialize_task_class(tmp_path):
52+
def test_python_unstructure(tmp_path):
5353

5454
assert Add(a=1, b=2)(cache_root=tmp_path / "cache1").out_int == 3
5555

56-
dct = serialize_task_class(Add)
56+
dct = unstructure(Add)
5757
assert isinstance(dct, dict)
5858
check_dict_fully_serialized(dct)
59-
Reloaded = unserialize_task_class(dct)
59+
Reloaded = structure(dct)
6060
assert get_fields(Add) == get_fields(Reloaded)
6161

6262
assert Reloaded(a=1, b=2)(cache_root=tmp_path / "cache2").out_int == 3
6363

6464

65-
def test_shell_serialize_task_class():
65+
def test_shell_unstructure():
6666

6767
MyCmd = shell.define(
6868
"my-cmd <in_file> <out|out_file> --an-arg <an_arg:int=2> --a-flag<a_flag>"
6969
)
7070

71-
dct = serialize_task_class(MyCmd)
71+
dct = unstructure(MyCmd)
7272
assert isinstance(dct, dict)
7373
check_dict_fully_serialized(dct)
74-
Reloaded = unserialize_task_class(dct)
74+
Reloaded = structure(dct)
7575
assert get_fields(MyCmd) == get_fields(Reloaded)
7676

7777

78-
def test_workflow_serialize_task_class(tmp_path):
78+
def test_workflow_unstructure(tmp_path):
7979

8080
@workflow.define(outputs=["out_file"])
8181
def AWorkflow(in_file: TextFile, a_param: int) -> TextFile:
@@ -84,10 +84,10 @@ def AWorkflow(in_file: TextFile, a_param: int) -> TextFile:
8484
)
8585
return concatenate.out_file
8686

87-
dct = serialize_task_class(AWorkflow)
87+
dct = unstructure(AWorkflow)
8888
assert isinstance(dct, dict)
8989
check_dict_fully_serialized(dct)
90-
Reloaded = unserialize_task_class(dct)
90+
Reloaded = structure(dct)
9191
assert get_fields(AWorkflow) == get_fields(Reloaded)
9292

9393
foo_file = tmp_path / "file1.txt"
@@ -97,7 +97,7 @@ def AWorkflow(in_file: TextFile, a_param: int) -> TextFile:
9797
assert outputs.out_file.contents == "foo\nfoo\nfoo\nfoo"
9898

9999

100-
def test_serialize_task_class_with_value_serializer():
100+
def test_unstructure_with_value_serializer():
101101

102102
@python.define
103103
def Identity(a: int) -> int:
@@ -121,13 +121,13 @@ def type_to_str_serializer(
121121
return value.__module__ + "." + value.__name__
122122
return value
123123

124-
dct = serialize_task_class(Identity, value_serializer=type_to_str_serializer)
124+
dct = unstructure(Identity, value_serializer=type_to_str_serializer)
125125
assert isinstance(dct, dict)
126126
check_dict_fully_serialized(dct)
127127
assert dct["inputs"] == {"a": {"type": "builtins.int", "help": "the arg"}}
128128

129129

130-
def test_serialize_task_class_with_filter():
130+
def test_unstructure_with_filter():
131131

132132
@python.define
133133
def Identity(a: int) -> int:
@@ -149,7 +149,7 @@ def no_helps_filter(atr: attrs.Attribute, value: ty.Any) -> bool:
149149
return False
150150
return filter_out_defaults(atr, value)
151151

152-
dct = serialize_task_class(Identity, filter=no_helps_filter)
152+
dct = unstructure(Identity, filter=no_helps_filter)
153153
assert isinstance(dct, dict)
154154
check_dict_fully_serialized(dct)
155155
assert dct["inputs"] == {"a": {"type": int}}

0 commit comments

Comments
 (0)