Skip to content

Commit 3e97cc7

Browse files
committed
cleaning up rebase, reintroduced with-classifier handling
1 parent bd478e2 commit 3e97cc7

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

nipype2pydra/task/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,9 +560,9 @@ def pydra_fld_input(self, field, nm):
560560
pos = pydra_metadata.get("position", None)
561561

562562
if pydra_default is not None and not pydra_metadata.get("mandatory", None):
563-
return (pydra_tp, pydra_default, pydra_metadata), pos
563+
return (pydra_type, pydra_default, pydra_metadata), pos
564564
else:
565-
return (pydra_tp, pydra_metadata), pos
565+
return (pydra_type, pydra_metadata), pos
566566

567567
def convert_output_spec(self, fields_from_template):
568568
"""creating fields list for pydra input spec"""

nipype2pydra/task/shell_command.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import re
22
import attrs
3+
import inspect
34
from .base import BaseTaskConverter
5+
from fileformats.core.mixin import WithClassifiers
46

57

68
@attrs.define
@@ -23,21 +25,32 @@ def generate_task_str(self, filename, input_fields, nonstd_types, output_fields)
2325
executable = self.nipype_interface.cmd
2426
if not isinstance(executable, str):
2527
raise RuntimeError(
26-
f"Could not find executable for {self.nipype_interface}"
28+
f"Could not find executable for {self.nipype_interface}, "
29+
"try the FunctionTaskConverter class instead"
2730
)
2831

32+
def unwrap_field_type(t):
33+
if issubclass(t, WithClassifiers) and t.is_classified:
34+
unwraped_classifiers = ", ".join(unwrap_field_type(c) for c in t.classifiers)
35+
return f"{t.unclassified.__name__}[{unwraped_classifiers}]"
36+
return t.__name__
37+
2938
def types_to_names(spec_fields):
3039
spec_fields_str = []
3140
for el in spec_fields:
3241
el = list(el)
33-
tp_str = str(el[1])
34-
if tp_str.startswith("<class "):
35-
tp_str = el[1].__name__
42+
field_type = el[1]
43+
if inspect.isclass(field_type) and issubclass(field_type, WithClassifiers):
44+
field_type_str = unwrap_field_type(field_type)
3645
else:
37-
# Alter modules in type string to match those that will be imported
38-
tp_str = tp_str.replace("typing", "ty")
39-
tp_str = re.sub(r"(\w+\.)+(?<!ty\.)(\w+)", r"\2", tp_str)
40-
el[1] = "#" + tp_str + "#"
46+
field_type_str = str(field_type)
47+
if field_type_str.startswith("<class "):
48+
field_type_str = el[1].__name__
49+
else:
50+
# Alter modules in type string to match those that will be imported
51+
field_type_str = field_type_str.replace("typing", "ty")
52+
field_type_str = re.sub(r"(\w+\.)+(?<!ty\.)(\w+)", r"\2", field_type_str)
53+
el[1] = "#" + field_type_str + "#"
4154
spec_fields_str.append(tuple(el))
4255
return spec_fields_str
4356

0 commit comments

Comments
 (0)