Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions niworkflows/utils/spaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,11 +708,17 @@ def __call__(self, parser, namespace, values, option_string=None):
if not values:
# option was called without any output spaces, so user does not want outputs
spaces.checkpoint()

invalid_spaces = []
for val in values:
val = val.rstrip(':')
space = val.split(':')[0]
if space in NONSTANDARD_REFERENCES and ':' in val:
invalid_spaces.append(val)

if (
val not in NONSTANDARD_REFERENCES
and not val.split(':')[0].startswith('fs')
space not in NONSTANDARD_REFERENCES
and not space.startswith('fs')
and ':res-' not in val
and ':resolution-' not in val
):
Expand All @@ -721,8 +727,16 @@ def __call__(self, parser, namespace, values, option_string=None):
# https://github.com/nipreps/niworkflows/pull/457#discussion_r375510227
# https://github.com/nipreps/niworkflows/pull/494
val = f'{val}:res-native'

for sp in Reference.from_string(val):
spaces.add(sp)

if invalid_spaces:
raise ValueError(
'Modifiers are not allowed for nonstandard spaces. '
f'Invalid space(s): {", ".join(invalid_spaces)}'
)

setattr(namespace, self.dest, spaces)


Expand Down
13 changes: 13 additions & 0 deletions niworkflows/utils/tests/test_spaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,16 @@ def test_space_action_edgecases(parser, flag, expected):
pargs = parser.parse_known_args(flag)[0]
spaces = pargs.spaces
assert spaces.is_cached() is expected


@pytest.mark.parametrize(
('spaces', 'expected'),
[
(('func:res-01',), 'Modifiers are not allowed for nonstandard spaces.'),
(('anat:den-91k',), 'Modifiers are not allowed for nonstandard spaces.'),
(('shouldraise',), 'space identifier "shouldraise" is invalid.'),
],
)
def test_space_action_invalid_spaces(parser, spaces, expected):
with pytest.raises(ValueError, match=expected):
parser.parse_known_args(args=('--spaces',) + spaces)[0]
Loading