Skip to content

Commit 60b61cf

Browse files
committed
starting to debug generic script for task conversions
1 parent 039d300 commit 60b61cf

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

nipype2pydra/cli.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ def cli():
2323
)
2424
@click.argument("spec-file", type=click.File())
2525
@click.argument("out-file", type=click.File(mode="w"))
26+
@click.option(
27+
"-c",
28+
"--callables",
29+
type=click.File(),
30+
default=None,
31+
help="a Python file containing callable functions required in the command interface",
32+
)
2633
@click.option(
2734
"-i",
2835
"--interface_name",
@@ -33,14 +40,14 @@ def cli():
3340
"provided all interfaces defined in the spec are converted"
3441
),
3542
)
36-
def task(spec_file, out_file, interface_name):
43+
def task(spec_file, out_file, interface_name, callables):
3744

3845
spec = yaml.safe_load(spec_file)
3946

4047
if interface_name:
4148
spec = {n: v for n, v in spec.items() if n in interface_name}
4249

43-
converter = TaskConverter(spec)
50+
converter = TaskConverter(spec, callables)
4451
code = converter.generate()
4552
out_file.write(code)
4653

nipype2pydra/task.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from pathlib import Path
33
import typing as ty
44
import inspect
5+
import sys
56
from importlib import import_module
67
from copy import copy
78
import black
@@ -57,7 +58,7 @@ class TaskConverter:
5758
("\'MultiOutputFile\'", "specs.MultiOutputFile"),
5859
]
5960

60-
def __init__(self, interface_spec, callables):
61+
def __init__(self, interface_spec, callables_file):
6162
self.interface_spec = copy(interface_spec)
6263
if self.interface_spec.get("output_requirements") is None:
6364
self.interface_spec["output_requirements"] = []
@@ -84,6 +85,10 @@ def __init__(self, interface_spec, callables):
8485
self.cmd = nipype_interface._cmd
8586
self.nipype_input_spec = nipype_interface.input_spec()
8687
self.nipype_output_spec = nipype_interface.output_spec()
88+
sys.path.append(str(Path(callables_file).resolve().parent))
89+
self.callables_module = import_module(Path(callables_file).stem)
90+
sys.path.pop()
91+
# import callablescallables
8792

8893
def pydra_specs(self, write=False, dirname=None):
8994
"""creating pydra input/output spec from nipype specs
@@ -398,7 +403,7 @@ def function_callables(self):
398403
fun_names = list(set(self.interface_spec["output_callables"].values()))
399404
fun_names.sort()
400405
for fun_nm in fun_names:
401-
fun = getattr(callables, fun_nm)
406+
fun = getattr(self.callables_module, fun_nm)
402407
fun_str += inspect.getsource(fun) + "\n"
403408
return fun_str
404409

0 commit comments

Comments
 (0)