Skip to content

Commit 3d0e218

Browse files
committed
debugging switch to class-symbols
1 parent 8c696fd commit 3d0e218

File tree

12 files changed

+890
-667
lines changed

12 files changed

+890
-667
lines changed

nipype2pydra/helpers.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
from types import ModuleType
1010
import black.report
1111
import yaml
12+
from .symbols import UsedSymbols
1213
from .utils import (
13-
UsedSymbols,
1414
extract_args,
1515
full_address,
1616
multiline_comment,
@@ -121,17 +121,13 @@ def nipype_object(self):
121121
return getattr(self.nipype_module, self.nipype_name)
122122

123123
@cached_property
124-
def used_symbols(self) -> UsedSymbols:
124+
def used(self) -> UsedSymbols:
125125
used = UsedSymbols.find(
126126
self.nipype_module,
127127
[self.src],
128+
package=self.package,
128129
collapse_intra_pkg=False,
129-
omit_classes=self.package.omit_classes,
130-
omit_modules=self.package.omit_modules,
131-
omit_functions=self.package.omit_functions,
132-
omit_constants=self.package.omit_constants,
133130
always_include=self.package.all_explicit,
134-
translations=self.package.all_import_translations,
135131
)
136132
used.import_stmts.update(i.to_statement() for i in self.imports)
137133
return used
@@ -147,10 +143,10 @@ def converted_code(self) -> ty.List[str]:
147143
@cached_property
148144
def nested_interfaces(self):
149145
potential_classes = {
150-
full_address(c[1]): c[0] for c in self.used_symbols.imported_classes if c[0]
146+
full_address(c[1]): c[0] for c in self.used.imported_classes if c[0]
151147
}
152148
potential_classes.update(
153-
(full_address(c), c.__name__) for c in self.used_symbols.classes
149+
(full_address(c), c.__name__) for c in self.used.classes
154150
)
155151
return {
156152
potential_classes[address]: workflow
@@ -377,8 +373,7 @@ class ClassConverter(BaseHelperConverter):
377373

378374
@cached_property
379375
def _converted_code(self) -> ty.Tuple[str, ty.List[str]]:
380-
"""Convert the Nipype workflow function to a Pydra workflow function and determine
381-
the configuration parameters that are used
376+
"""Convert a class into Pydra-
382377
383378
Returns
384379
-------
@@ -389,18 +384,30 @@ def _converted_code(self) -> ty.Tuple[str, ty.List[str]]:
389384
"""
390385

391386
used_configs = set()
392-
parts = re.split(
393-
r"\n (?!\s|\))", replace_undefined(self.src), flags=re.MULTILINE
394-
)
387+
388+
src = replace_undefined(self.src)[len("class ") :]
389+
name, bases, class_body = extract_args(src, drop_parens=True)
390+
bases = [
391+
b
392+
for b in bases
393+
if not self.package.is_omitted(getattr(self.nipype_module, b))
394+
]
395+
396+
parts = re.split(r"\n (?!\s|\))", class_body, flags=re.MULTILINE)
395397
converted_parts = []
396-
for part in parts:
398+
for part in parts[1:]:
397399
if part.startswith("def"):
398400
converted_func, func_used_configs = self._convert_function(part)
399401
converted_parts.append(converted_func)
400402
used_configs.update(func_used_configs)
401403
else:
402404
converted_parts.append(part)
403-
code_str = "\n ".join(converted_parts)
405+
code_str = (
406+
f"class {name}("
407+
+ ", ".join(bases)
408+
+ "):\n "
409+
+ "\n ".join(converted_parts)
410+
)
404411
# Format the the code before the find and replace so it is more predictable
405412
try:
406413
code_str = black.format_file_contents(

0 commit comments

Comments
 (0)