Skip to content

Commit d3010a2

Browse files
authored
Merge pull request #2082 from mwaskom/selectfiles_parse
ENH: Parse SelectFiles format keys to allow attribute access
2 parents ac050de + fd24535 commit d3010a2

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

nipype/interfaces/io.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,8 +1256,10 @@ def __init__(self, templates, **kwargs):
12561256
infields = []
12571257
for name, template in list(templates.items()):
12581258
for _, field_name, _, _ in string.Formatter().parse(template):
1259-
if field_name is not None and field_name not in infields:
1260-
infields.append(field_name)
1259+
if field_name is not None:
1260+
field_name = re.match("\w+", field_name).group()
1261+
if field_name not in infields:
1262+
infields.append(field_name)
12611263

12621264
self._infields = infields
12631265
self._outfields = list(templates)

nipype/interfaces/tests/test_io.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import os.path as op
1212
from subprocess import Popen
1313
import hashlib
14+
from collections import namedtuple
1415

1516
import pytest
1617
import nipype
@@ -62,6 +63,7 @@ def test_s3datagrabber():
6263
templates1 = {"model": "interfaces/{package}/model.py",
6364
"preprocess": "interfaces/{package}/pre*.py"}
6465
templates2 = {"converter": "interfaces/dcm{to!s}nii.py"}
66+
templates3 = {"model": "interfaces/{package.name}/model.py"}
6567

6668
@pytest.mark.parametrize("SF_args, inputs_att, expected", [
6769
({"templates":templates1}, {"package":"fsl"},
@@ -75,6 +77,11 @@ def test_s3datagrabber():
7577
7678
({"templates":templates2}, {"to":2},
7779
{"infields":["to"], "outfields":["converter"], "run_output":{"converter":op.join(op.dirname(nipype.__file__), "interfaces/dcm2nii.py")}, "node_output":["converter"]}),
80+
81+
({"templates": templates3}, {"package": namedtuple("package", ["name"])("fsl")},
82+
{"infields": ["package"], "outfields": ["model"],
83+
"run_output": {"model": op.join(op.dirname(nipype.__file__), "interfaces/fsl/model.py")},
84+
"node_output": ["model"]}),
7885
])
7986
def test_selectfiles(SF_args, inputs_att, expected):
8087
base_dir = op.dirname(nipype.__file__)

0 commit comments

Comments
 (0)