Skip to content

Commit

Permalink
move helper functions in core.py to helpers.py
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolocin committed Jul 23, 2020
1 parent 822bc94 commit 40ea9c3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
23 changes: 3 additions & 20 deletions pydra/engine/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
attr_fields,
)
from .helpers import (
is_task,
is_workflow,
is_lazy,
make_klass,
create_checksum,
print_help,
Expand Down Expand Up @@ -68,7 +71,6 @@ class TaskBase:
input_spec : : TODO
XXXX
cache_dir : :obj:`os.pathlike` or None
Path to directory to store cache. Save new cache here if prior cache couldn't be
found here or in `cache_locations`.
Expand Down Expand Up @@ -305,7 +307,6 @@ def checksum_states(self, state_index=None):
----------
state_index :
TODO
"""
self.state.prepare_states(self.inputs)
self.state.prepare_inputs()
Expand Down Expand Up @@ -1067,21 +1068,3 @@ def _collect_outputs(self):
else:
raise ValueError(f"Task {val.name} raised an error")
return attr.evolve(output, **output_wf)


def is_task(obj):
"""Check whether an object looks like a task."""
return hasattr(obj, "_run_task")


def is_workflow(obj):
"""Check whether an object is a :class:`Workflow` instance."""
return isinstance(obj, Workflow)


def is_lazy(obj):
"""Check whether an object has any field that is a Lazy Field"""
for f in attr_fields(obj):
if isinstance(getattr(obj, f.name), LazyField):
return True
return False
18 changes: 18 additions & 0 deletions pydra/engine/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,24 @@
from .helpers_file import hash_file, hash_dir, copyfile, is_existing_file


def is_task(obj):
"""Check whether an object looks like a task."""
return hasattr(obj, "_run_task")


def is_workflow(obj):
"""Check whether an object is a :class:`Workflow` instance."""
return isinstance(obj, Workflow)


def is_lazy(obj):
"""Check whether an object has any field that is a Lazy Field"""
for f in attr_fields(obj):
if isinstance(getattr(obj, f.name), LazyField):
return True
return False


def ensure_list(obj, tuple2list=False):
"""
Return a list whatever the input object is.
Expand Down

0 comments on commit 40ea9c3

Please sign in to comment.