Merge "Add more comments to flow/task"
This commit is contained in:
@@ -27,12 +27,22 @@ from taskflow.utils import reflection
|
|||||||
class Flow(six.with_metaclass(abc.ABCMeta)):
|
class Flow(six.with_metaclass(abc.ABCMeta)):
|
||||||
"""The base abstract class of all flow implementations.
|
"""The base abstract class of all flow implementations.
|
||||||
|
|
||||||
It provides a name and an identifier (uuid or other) to the flow so that
|
It provides a name and an identifier (uuid) to the flow so that it can be
|
||||||
it can be uniquely identifed among many flows.
|
uniquely identifed among many flows while executing or while referencing
|
||||||
|
the results (or other metadata) of this flow in storage.
|
||||||
|
|
||||||
Flows are expected to provide the following methods:
|
NOTE(harlowja): if a flow is placed in another flow as a subflow, a desired
|
||||||
|
way to compose flows together, then it is valid and permissible that during
|
||||||
|
execution the subflow & parent flow may be flattened into a new flow. Since
|
||||||
|
a flow is just a 'structuring' concept this is typically a behavior that
|
||||||
|
should not be worried about (as it is not visible to the user), but it is
|
||||||
|
worth mentioning here.
|
||||||
|
|
||||||
|
Flows are expected to provide the following methods/properties:
|
||||||
- add
|
- add
|
||||||
- __len__
|
- __len__
|
||||||
|
- requires
|
||||||
|
- provides
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, name, uuid=None):
|
def __init__(self, name, uuid=None):
|
||||||
@@ -49,6 +59,7 @@ class Flow(six.with_metaclass(abc.ABCMeta)):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def uuid(self):
|
def uuid(self):
|
||||||
|
"""A unique identifier for this flow"""
|
||||||
return self._id
|
return self._id
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
@@ -69,8 +80,8 @@ class Flow(six.with_metaclass(abc.ABCMeta)):
|
|||||||
|
|
||||||
@abc.abstractproperty
|
@abc.abstractproperty
|
||||||
def requires(self):
|
def requires(self):
|
||||||
"""Browse flow requirements."""
|
"""Browse argument requirement names this flow requires to run."""
|
||||||
|
|
||||||
@abc.abstractproperty
|
@abc.abstractproperty
|
||||||
def provides(self):
|
def provides(self):
|
||||||
"""Browse values provided by the flow."""
|
"""Browse argument names provided by the flow."""
|
||||||
|
|||||||
@@ -59,6 +59,12 @@ def _save_as_to_mapping(save_as):
|
|||||||
|
|
||||||
|
|
||||||
def _build_rebind_dict(args, rebind_args):
|
def _build_rebind_dict(args, rebind_args):
|
||||||
|
"""Build a argument remapping/rebinding dictionary.
|
||||||
|
|
||||||
|
This dictionary allows a task to declare that it will take a needed
|
||||||
|
requirement bound to a given name with another name instead (mapping the
|
||||||
|
new name onto the required name).
|
||||||
|
"""
|
||||||
if rebind_args is None:
|
if rebind_args is None:
|
||||||
return {}
|
return {}
|
||||||
elif isinstance(rebind_args, (list, tuple)):
|
elif isinstance(rebind_args, (list, tuple)):
|
||||||
@@ -86,6 +92,11 @@ def _check_args_mapping(task_name, rebind, args, accepts_kwargs):
|
|||||||
|
|
||||||
|
|
||||||
def _build_arg_mapping(task_name, reqs, rebind_args, function, do_infer):
|
def _build_arg_mapping(task_name, reqs, rebind_args, function, do_infer):
|
||||||
|
"""Given a function, its requirements and a rebind mapping this helper
|
||||||
|
function will build the correct argument mapping for the given function as
|
||||||
|
well as verify that the final argument mapping does not have missing or
|
||||||
|
extra arguments (where applicable).
|
||||||
|
"""
|
||||||
task_args = reflection.get_required_callable_args(function)
|
task_args = reflection.get_required_callable_args(function)
|
||||||
accepts_kwargs = reflection.accepts_kwargs(function)
|
accepts_kwargs = reflection.accepts_kwargs(function)
|
||||||
result = {}
|
result = {}
|
||||||
|
|||||||
Reference in New Issue
Block a user