Skip to content

Commit

Permalink
Merge pull request #20 from nipype/updated-conv
Browse files Browse the repository at this point in the history
Updated nipype converter
  • Loading branch information
tclose authored May 18, 2024
2 parents e3f776b + ad94378 commit 9709397
Show file tree
Hide file tree
Showing 101 changed files with 7,566 additions and 7,603 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ jobs:
- name: Generate post-release tag based on Nipype and Nipype2Pydra versions
id: post_release_tag
run: |
POST=$(python -c "from pydra.tasks.ants.auto._version import *; print(post_release)")
POST=$(python -c "from pydra.tasks.ants.auto._post_release import *; print(post_release)")
echo "TAG=${{ steps.latest_tag.outputs.TAG }}post${POST}" >> $GITHUB_OUTPUT
- name: Add auto directory to git repo
Expand Down
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
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
from tqdm import tqdm
import yaml
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 = "ants"

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/..
145 changes: 0 additions & 145 deletions nipype-auto-conv/specs/affine_initializer.yaml

This file was deleted.

133 changes: 0 additions & 133 deletions nipype-auto-conv/specs/ai.yaml

This file was deleted.

Loading

0 comments on commit 9709397

Please sign in to comment.