Skip to content

fix: handle automatic module creation, name extraction, default value #2490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 9, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 7 additions & 3 deletions nipype/utils/nipype2boutiques.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import (print_function, division, unicode_literals,
absolute_import)

from builtins import str, open
from builtins import str, open, bytes
# This tool exports a Nipype interface in the Boutiques (https://github.com/boutiques) JSON format.
# Boutiques tools can be imported in CBRAIN (https://github.com/aces/cbrain) among other platforms.
#
Expand Down Expand Up @@ -40,10 +40,12 @@ def generate_boutiques_descriptor(
raise Exception("Undefined module.")

# Retrieves Nipype interface
if isinstance(module, str):
if isinstance(module, (str, bytes)):
import_module(module)
module_name = str(module)
module = sys.modules[module]
else:
module_name = str(module.__name__)

interface = getattr(module, interface_name)()
inputs = interface.input_spec()
Expand Down Expand Up @@ -249,7 +251,7 @@ def create_tempfile():
Creates a temp file and returns its name.
'''
fileTemp = tempfile.NamedTemporaryFile(delete=False)
fileTemp.write("hello")
fileTemp.write(b"hello")
fileTemp.close()
return fileTemp.name

Expand Down Expand Up @@ -283,6 +285,8 @@ def must_generate_value(name, type, ignored_template_inputs, spec_info, spec,
# Best guess to detect string restrictions...
if "' or '" in spec_info:
return False
if spec.default or spec.default_value():
return False
if not ignored_template_inputs:
return True
return not (name in ignored_template_inputs)
17 changes: 17 additions & 0 deletions nipype/utils/tests/test_nipype2boutiques.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
from future import standard_library
standard_library.install_aliases()

from ..nipype2boutiques import generate_boutiques_descriptor


def test_generate():
generate_boutiques_descriptor(module='nipype.interfaces.ants.registration',
interface_name='ANTS',
ignored_template_inputs=(),
docker_image=None,
docker_index=None,
verbose=False,
ignore_template_numbers=False)