Skip to content

Commit 86e2f65

Browse files
committed
moved all generated code for interface only packages into auto directory
1 parent 36ec55b commit 86e2f65

File tree

2 files changed

+36
-21
lines changed

2 files changed

+36
-21
lines changed

nipype2pydra/cli/convert.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,6 @@ def convert(
6868
output_dir = package_dir / "auto" if converter.interface_only else package_dir
6969
if output_dir.exists():
7070
shutil.rmtree(output_dir)
71-
nipype_ports_dir = package_dir / "nipype_ports"
72-
if nipype_ports_dir.exists():
73-
shutil.rmtree(nipype_ports_dir)
7471

7572
# Load interface specs
7673
for fspath in interface_yamls:

nipype2pydra/package.py

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -289,12 +289,25 @@ def nipype_module(self):
289289

290290
@property
291291
def all_import_translations(self) -> ty.List[ty.Tuple[str, str]]:
292-
return self.import_translations + [
292+
all_translations = self.import_translations + [
293293
(r"nipype\.interfaces\.mrtrix3.\w+\b", r"pydra.tasks.mrtrix3.v3_0"),
294294
(r"nipype\.interfaces\.(?!base)(\w+)\b", r"pydra.tasks.\1.auto"),
295-
(r"nipype\.(.*)", self.name + r".nipype_ports.\1"),
296-
(self.nipype_name, self.name),
297295
]
296+
if self.interface_only:
297+
all_translations.extend(
298+
[
299+
(r"nipype\.(.*)", self.name + r".auto.nipype_ports.\1"),
300+
(self.nipype_name, self.name + ".auto"),
301+
]
302+
)
303+
else:
304+
all_translations.extend(
305+
[
306+
(r"nipype\.(.*)", self.name + r".nipype_ports.\1"),
307+
(self.nipype_name, self.name),
308+
]
309+
)
310+
return all_translations
298311

299312
@property
300313
def all_omit_modules(self) -> ty.List[str]:
@@ -450,7 +463,7 @@ def collect_intra_pkg_objects(used: UsedSymbols, port_nipype: bool = True):
450463
".".join(cp_pkg.split(".")[1:]),
451464
)
452465
output_pkg_fspath = self.to_fspath(
453-
package_root, self.to_output_module_path(cp_pkg)
466+
package_root, self.nipype2pydra_module_name(cp_pkg)
454467
)
455468
output_pkg_fspath.parent.mkdir(parents=True, exist_ok=True)
456469
shutil.copytree(
@@ -508,7 +521,7 @@ def write_intra_pkg_modules(
508521
if not objs:
509522
continue
510523

511-
out_mod_name = self.to_output_module_path(mod_name)
524+
out_mod_name = self.nipype2pydra_module_name(mod_name)
512525

513526
if mod_name == self.name:
514527
raise NotImplementedError(
@@ -568,7 +581,7 @@ def write_intra_pkg_modules(
568581
import_find_replace=self.import_find_replace,
569582
)
570583

571-
def to_output_module_path(self, nipype_module_path: str) -> str:
584+
def nipype2pydra_module_name(self, nipype_name: str) -> str:
572585
"""Converts an original Nipype module path to a Pydra module path
573586
574587
Parameters
@@ -581,17 +594,20 @@ def to_output_module_path(self, nipype_module_path: str) -> str:
581594
str
582595
the Pydra module path
583596
"""
584-
base_pkg = self.name + ".__init__"
585-
relative_to = self.nipype_name
586-
if re.match(self.nipype_module.__name__ + r"\b", nipype_module_path):
587-
if self.interface_only:
588-
base_pkg = self.name + ".auto.__init__"
589-
elif re.match(r"^nipype\b", nipype_module_path):
590-
base_pkg = self.name + ".nipype_ports.__init__"
597+
if self.interface_only:
598+
base_pkg = self.name + ".auto"
599+
else:
600+
base_pkg = self.name
601+
if re.match(self.nipype_module.__name__ + r"\b", nipype_name):
602+
relative_to = self.nipype_name
603+
elif re.match(r"^nipype\b", nipype_name):
604+
base_pkg += ".nipype_ports"
591605
relative_to = "nipype"
606+
else:
607+
return nipype_name
592608
return ImportStatement.join_relative_package(
593-
base_pkg,
594-
ImportStatement.get_relative_package(nipype_module_path, relative_to),
609+
base_pkg + ".__init__",
610+
ImportStatement.get_relative_package(nipype_name, relative_to),
595611
)
596612

597613
@classmethod
@@ -684,9 +700,11 @@ def nipype_port_converters(self) -> ty.Dict[str, interface.BaseInterfaceConverte
684700
with open(spec_file, "r") as f:
685701
spec = yaml.safe_load(f)
686702
callables_file = spec_file.parent / (spec_file.stem + "_callables.py")
687-
module_name = ".".join(
688-
[self.name, "nipype_ports"] + spec["nipype_module"].split(".")[1:]
689-
)
703+
if self.interface_only:
704+
mod_base = [self.name, "auto", "nipype_ports"]
705+
else:
706+
mod_base = [self.name, "nipype_ports"]
707+
module_name = ".".join(mod_base + spec["nipype_module"].split(".")[1:])
690708
task_name = spec["task_name"]
691709
output_module = (
692710
self.translate_submodule(

0 commit comments

Comments
 (0)