Skip to content

debugging running tests #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
c97e489
debugging running tests
tclose May 29, 2024
caee1bc
fixing defaults for function interfaces
tclose May 29, 2024
5e8da87
set mandatory to False when there is a valid default
tclose May 29, 2024
843a83a
added support for _format_arg and _parse_inputs methods
tclose May 31, 2024
07700f2
debugging reworked _list_outputs handling
tclose May 31, 2024
985ab46
handled super methods properly
tclose May 31, 2024
1bcc2ec
added callables to outputs
tclose Jun 1, 2024
68e09c7
touching up format_arg super handling
tclose Jun 1, 2024
b550966
handling special super methods
tclose Jun 1, 2024
28659bc
fixed handling of super methods, added supported for aggregate_output…
tclose Jun 1, 2024
1e92a40
debugged changes so that all packages build successfully again
tclose Jun 1, 2024
63a4077
finally got all packages to convert again!
tclose Jun 1, 2024
0aa80aa
debugging updates to conversions to handle function task super methods
tclose Jun 2, 2024
3591c7b
all packages build again after refactor
tclose Jun 2, 2024
23ebaa4
moved constants to bottom of file just in case they rely on a local f…
tclose Jun 2, 2024
dc3214f
disabled return dict unwrapping (used in _list_outputs) by default. A…
tclose Jun 3, 2024
0cac4cd
added option to explicitly route connections from/to explicit inputs …
tclose Jun 3, 2024
955e6c8
debugged workflows and spatial normalisation monster interface
tclose Jun 3, 2024
abf3551
unwrapped super methods in shell helper methods
tclose Jun 3, 2024
8c696fd
debugging mriqc/niworkflows conversions
tclose Jun 7, 2024
3d0e218
debugging switch to class-symbols
tclose Jul 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions example-specs/pkg-gen/niworkflows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ niworkflows:
- niworkflows.interfaces.bids.ReadSidecarJSON
- niworkflows.interfaces.fixes.FixHeaderApplyTransforms
- niworkflows.interfaces.fixes.FixN4BiasFieldCorrection
- niworkflows.interfaces.fixes.FixHeaderRegistration
- niworkflows.interfaces.header.SanitizeImage
- niworkflows.interfaces.images.RobustAverage
- niworkflows.interfaces.morphology.BinaryDilation
Expand Down
9 changes: 7 additions & 2 deletions nipype2pydra/cli/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,15 @@ def convert(
# Clean previous version of output dir
package_dir = converter.package_dir(package_root)
if converter.interface_only:
shutil.rmtree(package_dir / "auto")
auto_dir = package_dir / "auto"
if auto_dir.exists():
shutil.rmtree(auto_dir)
else:
for fspath in package_dir.iterdir():
if fspath == package_dir / "__init__.py":
if fspath.parent == package_dir and fspath.name in (
"_version.py",
"__init__.py",
):
continue
if fspath.is_dir():
shutil.rmtree(fspath)
Expand Down
45 changes: 26 additions & 19 deletions nipype2pydra/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from types import ModuleType
import black.report
import yaml
from .symbols import UsedSymbols
from .utils import (
UsedSymbols,
extract_args,
full_address,
multiline_comment,
Expand Down Expand Up @@ -121,19 +121,15 @@ def nipype_object(self):
return getattr(self.nipype_module, self.nipype_name)

@cached_property
def used_symbols(self) -> UsedSymbols:
def used(self) -> UsedSymbols:
used = UsedSymbols.find(
self.nipype_module,
[self.src],
package=self.package,
collapse_intra_pkg=False,
omit_classes=self.package.omit_classes,
omit_modules=self.package.omit_modules,
omit_functions=self.package.omit_functions,
omit_constants=self.package.omit_constants,
always_include=self.package.all_explicit,
translations=self.package.all_import_translations,
)
used.imports.update(i.to_statement() for i in self.imports)
used.import_stmts.update(i.to_statement() for i in self.imports)
return used

@cached_property
Expand All @@ -147,12 +143,10 @@ def converted_code(self) -> ty.List[str]:
@cached_property
def nested_interfaces(self):
potential_classes = {
full_address(c[1]): c[0]
for c in self.used_symbols.intra_pkg_classes
if c[0]
full_address(c[1]): c[0] for c in self.used.imported_classes if c[0]
}
potential_classes.update(
(full_address(c), c.__name__) for c in self.used_symbols.local_classes
(full_address(c), c.__name__) for c in self.used.classes
)
return {
potential_classes[address]: workflow
Expand Down Expand Up @@ -350,6 +344,7 @@ def _converted_code(self) -> ty.Tuple[str, ty.List[str]]:
# Write to file for debugging
debug_file = "~/unparsable-nipype2pydra-output.py"
with open(Path(debug_file).expanduser(), "w") as f:
f.write(f"# Attemping to convert {self.full_name}\n")
f.write(code_str)
raise RuntimeError(
f"Black could not parse generated code (written to {debug_file}): "
Expand Down Expand Up @@ -378,8 +373,7 @@ class ClassConverter(BaseHelperConverter):

@cached_property
def _converted_code(self) -> ty.Tuple[str, ty.List[str]]:
"""Convert the Nipype workflow function to a Pydra workflow function and determine
the configuration parameters that are used
"""Convert a class into Pydra-

Returns
-------
Expand All @@ -390,18 +384,30 @@ def _converted_code(self) -> ty.Tuple[str, ty.List[str]]:
"""

used_configs = set()
parts = re.split(
r"\n (?!\s|\))", replace_undefined(self.src), flags=re.MULTILINE
)

src = replace_undefined(self.src)[len("class ") :]
name, bases, class_body = extract_args(src, drop_parens=True)
bases = [
b
for b in bases
if not self.package.is_omitted(getattr(self.nipype_module, b))
]

parts = re.split(r"\n (?!\s|\))", class_body, flags=re.MULTILINE)
converted_parts = []
for part in parts:
for part in parts[1:]:
if part.startswith("def"):
converted_func, func_used_configs = self._convert_function(part)
converted_parts.append(converted_func)
used_configs.update(func_used_configs)
else:
converted_parts.append(part)
code_str = "\n ".join(converted_parts)
code_str = (
f"class {name}("
+ ", ".join(bases)
+ "):\n "
+ "\n ".join(converted_parts)
)
# Format the the code before the find and replace so it is more predictable
try:
code_str = black.format_file_contents(
Expand All @@ -413,6 +419,7 @@ def _converted_code(self) -> ty.Tuple[str, ty.List[str]]:
# Write to file for debugging
debug_file = "~/unparsable-nipype2pydra-output.py"
with open(Path(debug_file).expanduser(), "w") as f:
f.write(f"# Attemping to convert {self.full_name}\n")
f.write(code_str)
raise RuntimeError(
f"Black could not parse generated code (written to {debug_file}): "
Expand Down
Loading
Loading