generated from nipype/pydra-tasks-template
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from nipype/updated-conv
Updated nipype converter
- Loading branch information
Showing
101 changed files
with
7,566 additions
and
7,603 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/.. |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.