diff --git a/.gitignore b/.gitignore index 0d32122..2a3a1a2 100644 --- a/.gitignore +++ b/.gitignore @@ -165,3 +165,4 @@ cython_debug/ # Generated files /pydra/tasks/ants/_version.py /pydra/tasks/ants/auto +/pydra/tasks/ants/nipype_ports diff --git a/nipype-auto-conv/specs/classes/nipype.interfaces.ants.base.Info.yaml b/nipype-auto-conv/specs/classes/nipype.interfaces.ants.base.Info.yaml new file mode 100644 index 0000000..0979499 --- /dev/null +++ b/nipype-auto-conv/specs/classes/nipype.interfaces.ants.base.Info.yaml @@ -0,0 +1,11 @@ +# name of the converted workflow constructor function +name: Info +# name of the nipype workflow constructor +nipype_name: Info +# name of the nipype module the function is found within, e.g. mriqc.workflows.anatomical.base +nipype_module: nipype.interfaces.ants.base +# the names of the nested interfaces that are defined in other modules and need to be imported +external_nested_interfaces: null +# a list of tuples where the first element is a regular expression to find in the code and the second +# element is the replacement string +find_replace: null diff --git a/nipype-auto-conv/specs/classes/nipype.interfaces.base.core.PackageInfo.yaml b/nipype-auto-conv/specs/classes/nipype.interfaces.base.core.PackageInfo.yaml new file mode 100644 index 0000000..818a558 --- /dev/null +++ b/nipype-auto-conv/specs/classes/nipype.interfaces.base.core.PackageInfo.yaml @@ -0,0 +1,20 @@ +# name of the converted workflow constructor function +name: PackageInfo +# name of the nipype workflow constructor +nipype_name: PackageInfo +# name of the nipype module the function is found within, e.g. mriqc.workflows.anatomical.base +nipype_module: nipype.interfaces.base.core +# the names of the nested interfaces that are defined in other modules and need to be imported +external_nested_interfaces: null +# a list of tuples where the first element is a regular expression to find in the code and the second +# element is the replacement string +find_replace: + - ["import logging", "import logging\\nimport subprocess as sp"] + - [ + "\\n(\\s+)clout = CommandLine\\(\\s*command=([^,]+).+?\\).run\\(\\)", + "\\n\\1raw_info = sp.check_output(\\2, shell=True).decode('utf-8')", + ] + - ["raw_info = clout\\.runtime\\.stdout", ""] +imports: + - module: subprocess + alias: sp diff --git a/pydra/tasks/ants/base.py b/pydra/tasks/ants/base.py new file mode 100644 index 0000000..f2040cd --- /dev/null +++ b/pydra/tasks/ants/base.py @@ -0,0 +1,35 @@ +import logging +import os +from packaging.version import Version, parse + + +logger = logging.getLogger(__name__) + + +class Info(PackageInfo): + version_cmd = ( + os.path.join(os.getenv("ANTSPATH", ""), "antsRegistration") + " --version" + ) + + @staticmethod + def parse_version(raw_info): + for line in raw_info.splitlines(): + if line.startswith("ANTs Version: "): + v_string = line.split()[2] + break + else: + return None + + # -githash may or may not be appended + v_string = v_string.split("-")[0] + + version = parse(v_string) + + # Known mislabeled versions + if version.is_postrelease: + if version.base_version == "2.1.0" and version.post >= 789: + return "2.2.0" + + # Unless we know of a specific reason to re-version, we will + # treat the base version (before pre/post/dev) as authoritative + return version.base_version