Skip to content

Commit

Permalink
Added Info class to package via explicit inclusion
Browse files Browse the repository at this point in the history
  • Loading branch information
tclose committed Apr 27, 2024
1 parent 4ef56b3 commit 5452ef3
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,4 @@ cython_debug/
# Generated files
/pydra/tasks/ants/_version.py
/pydra/tasks/ants/auto
/pydra/tasks/ants/nipype_ports
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions pydra/tasks/ants/base.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5452ef3

Please sign in to comment.