Skip to content

Commit f2e6c32

Browse files
committed
fixed up sorting of inserted method args and xors for deterministic generation
1 parent 992d873 commit f2e6c32

File tree

5 files changed

+15
-12
lines changed

5 files changed

+15
-12
lines changed

nipype2pydra/interface/base.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,7 @@ def process_method(
11591159
pass
11601160
if "runtime" in args:
11611161
args.remove("runtime")
1162-
args_to_add = list(self.used.method_args.get(method.__name__, [])) + list(
1162+
args_to_add = sorted(self.used.method_args.get(method.__name__, [])) + sorted(
11631163
additional_args
11641164
)
11651165
if args_to_add:
@@ -1338,7 +1338,7 @@ def unwrap_nested_methods(
13381338
)
13391339
# Insert additional arguments to the method call (which were previously
13401340
# accessed via member attributes)
1341-
args_to_be_inserted = list(self.used.method_args[name]) + list(
1341+
args_to_be_inserted = sorted(self.used.method_args[name]) + sorted(
13421342
additional_args
13431343
)
13441344
try:
@@ -1405,8 +1405,7 @@ def unwrap_nested_methods(
14051405
"trait_modified",
14061406
]
14071407

1408-
CONFTEST = """
1409-
# For debugging in IDE's don't catch raised exceptions and let the IDE
1408+
CONFTEST = """# For debugging in IDE's don't catch raised exceptions and let the IDE
14101409
# break at it
14111410
import os
14121411
import pytest
@@ -1423,7 +1422,7 @@ def pytest_internalerror(excinfo):
14231422
raise excinfo.value # raise internal errors instead of capturing them
14241423
14251424
def pytest_configure(config):
1426-
config.option.capture = 'no' # allow print statements to show up in the console
1425+
config.option.capture = "no" # allow print statements to show up in the console
14271426
config.option.log_cli = True # show log messages in the console
14281427
config.option.log_level = "INFO" # set the log level to INFO
14291428

nipype2pydra/interface/shell.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,9 @@ def generate_code(self, input_fields, nonstd_types, output_fields) -> str:
190190

191191
spec_str += "@shell.define"
192192
if xor_sets:
193-
spec_str += f"(xor={[list(x) for x in xor_sets]})"
193+
spec_str += (
194+
f"(xor={[list(x) for x in sorted(tuple(sorted(s)) for s in xor_sets)]})"
195+
)
194196
spec_str += (
195197
f"\nclass {self.task_name}(shell.Task['{self.task_name}.Outputs']):\n"
196198
)

nipype2pydra/package.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ def write_post_release_file(self, fspath: Path):
708708
src_pkg_version = "{src_pkg_version}"
709709
nipype2pydra_version = "{nipype2pydra_version}"
710710
post_release = "{post_release}"
711-
"""
711+
"""
712712
)
713713

714714
@classmethod

nipype2pydra/statements/imports.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ def __str__(self):
217217
if self.from_:
218218
imported_str = ", ".join(str(i) for i in sorted(self.imported.values()))
219219
module = self.translation if self.translation else self.from_
220+
# Drop trailing hidden module (e.g. '_local' from 'pathlib._local')
221+
if module.split(".")[-1].startswith("_"):
222+
module = ".".join(module.split(".")[:-1])
220223
stmt_str = f"{self.indent}from {module} import {imported_str}"
221224
elif self.translation:
222225
stmt_str = f"{self.indent}import {self.translation}"
@@ -614,7 +617,7 @@ def to_statement(self):
614617

615618

616619
def from_list_to_imports(
617-
obj: ty.Union[ty.List[ExplicitImport], list]
620+
obj: ty.Union[ty.List[ExplicitImport], list],
618621
) -> ty.List[ExplicitImport]:
619622
if obj is None:
620623
return []

nipype2pydra/workflow.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545

4646
def convert_node_prefixes(
47-
nodes: ty.Union[ty.Dict[str, str], ty.Sequence[ty.Union[ty.Tuple[str, str], str]]]
47+
nodes: ty.Union[ty.Dict[str, str], ty.Sequence[ty.Union[ty.Tuple[str, str], str]]],
4848
) -> ty.Dict[str, str]:
4949
if isinstance(nodes, dict):
5050
nodes_it = nodes.items()
@@ -1310,8 +1310,7 @@ def default_spec(
13101310
)
13111311
return yaml_str
13121312

1313-
CONFTEST = """
1314-
# For debugging in IDE's don't catch raised exceptions and let the IDE
1313+
CONFTEST = """# For debugging in IDE's don't catch raised exceptions and let the IDE
13151314
# break at it
13161315
import os
13171316
import pytest
@@ -1328,7 +1327,7 @@ def pytest_internalerror(excinfo):
13281327
raise excinfo.value # raise internal errors instead of capturing them
13291328
13301329
def pytest_configure(config):
1331-
config.option.capture = 'no' # allow print statements to show up in the console
1330+
config.option.capture = "no" # allow print statements to show up in the console
13321331
config.option.log_cli = True # show log messages in the console
13331332
config.option.log_level = "INFO" # set the log level to INFO
13341333

0 commit comments

Comments
 (0)