Skip to content

Commit

Permalink
updated specification syntax to match latest workflow-src branch of n…
Browse files Browse the repository at this point in the history
…ipype2pydra
  • Loading branch information
tclose committed May 3, 2024
1 parent 1386dec commit 39ec109
Show file tree
Hide file tree
Showing 181 changed files with 11 additions and 91 deletions.
84 changes: 3 additions & 81 deletions nipype-auto-conv/generate
Original file line number Diff line number Diff line change
@@ -1,81 +1,3 @@
#!/usr/bin/env python3
import sys
import os.path
from warnings import warn
from pathlib import Path
import shutil
from importlib import import_module
import yaml
from tqdm import tqdm
import nipype
import nipype2pydra.utils
from nipype2pydra.task import get_converter


SPECS_DIR = Path(__file__).parent / "specs"
PKG_ROOT = Path(__file__).parent.parent
PKG_NAME = "freesurfer"

if ".dev" in nipype.__version__:
raise RuntimeError(
f"Cannot use a development version of Nipype {nipype.__version__}"
)

if ".dev" in nipype2pydra.__version__:
warn(
f"using development version of nipype2pydra ({nipype2pydra.__version__}), "
f"development component will be dropped in {PKG_NAME} package version"
)

# Insert specs dir into path so we can load callables modules
sys.path.insert(0, str(SPECS_DIR))

auto_init = f"# Auto-generated by {__file__}, do not edit as it will be overwritten\n\n"

auto_dir = PKG_ROOT / "pydra" / "tasks" / PKG_NAME / "auto"
if auto_dir.exists():
shutil.rmtree(auto_dir)

all_interfaces = []
for fspath in tqdm(
sorted(SPECS_DIR.glob("**/*.yaml")), "converting interfaces from Nipype to Pydra"
):
with open(fspath) as f:
spec = yaml.load(f, Loader=yaml.SafeLoader)

rel_pkg_path = str(fspath.parent.relative_to(SPECS_DIR)).replace(os.path.sep, ".")
if rel_pkg_path == ".":
rel_pkg_path = fspath.stem
else:
rel_pkg_path += "." + fspath.stem

callables = import_module(rel_pkg_path + "_callables")

module_name = nipype2pydra.utils.to_snake_case(spec["task_name"])

converter = get_converter(
output_module=f"pydra.tasks.{PKG_NAME}.auto.{module_name}",
callables_module=callables, # type: ignore
**spec,
)
converter.generate(PKG_ROOT)
auto_init += f"from .{module_name} import {converter.task_name}\n"
all_interfaces.append(converter.task_name)


with open(PKG_ROOT / "pydra" / "tasks" / PKG_NAME / "auto" / "_version.py", "w") as f:
f.write(
f"""# Auto-generated by {__file__}, do not edit as it will be overwritten
nipype_version = "{nipype.__version__.split('.dev')[0]}"
nipype2pydra_version = "{nipype2pydra.__version__.split('.dev')[0]}"
post_release = (nipype_version + nipype2pydra_version).replace(".", "")
"""
)

auto_init += (
"\n\n__all__ = [\n" + "\n".join(f' "{i}",' for i in all_interfaces) + "\n]\n"
)

with open(PKG_ROOT / "pydra" / "tasks" / PKG_NAME / "auto" / "__init__.py", "w") as f:
f.write(auto_init)
#!/usr/bin/env bash
conv_dir=$(dirname $0)
nipype2pydra convert $conv_dir/specs $conv_dir/..
10 changes: 0 additions & 10 deletions nipype-auto-conv/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,2 @@
black
attrs>=22.1.0
nipype
tqdm
pydra
PyYAML>=6.0
fileformats >=0.8
fileformats-medimage >=0.4
fileformats-datascience >= 0.1
fileformats-medimage-freesurfer
traits
nipype2pydra
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions nipype-auto-conv/specs/package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# name of the package to generate, e.g. pydra.tasks.mriqc
name: pydra.tasks.freesurfer
# name of the nipype package to generate from (e.g. mriqc)
nipype_name: nipype.interfaces.freesurfer
# The name of the global struct/dict that contains workflow inputs that are to be converted to inputs of the function along with the type of the struct, either "dict" or "class"
config_params: null
# Mappings between nipype packages and their pydra equivalents. Regular expressions are supported
import_translations: null

0 comments on commit 39ec109

Please sign in to comment.