From 9443506b9367ffba585468315dfe00a6b5c20039 Mon Sep 17 00:00:00 2001 From: Changbin Liu Date: Fri, 30 Aug 2013 17:12:54 -0400 Subject: [PATCH] Rename "revert_with" => "revert" and "execute_with" to "execute" "_with" is kind of obvious, and also less typing for users of this library Change-Id: I99f597dae5612cc44cc7f19ae144776f63d32bac --- taskflow/decorators.py | 4 ++-- taskflow/examples/complex_graph.py | 2 +- taskflow/examples/reverting_linear.py | 4 ++-- taskflow/task.py | 22 +++++++++++----------- taskflow/tests/unit/test_decorators.py | 2 +- taskflow/tests/unit/test_functor_task.py | 2 +- taskflow/tests/unit/test_graph_flow.py | 2 +- taskflow/tests/unit/test_linear_flow.py | 2 +- taskflow/tests/unit/test_threaded_flow.py | 2 +- 9 files changed, 21 insertions(+), 21 deletions(-) diff --git a/taskflow/decorators.py b/taskflow/decorators.py index 1c5c0734..8230eb1a 100644 --- a/taskflow/decorators.py +++ b/taskflow/decorators.py @@ -72,13 +72,13 @@ def task(*args, **kwargs): """Decorates a given function so that it can be used as a task""" def decorator(f): - def task_factory(execute_with, **factory_kwargs): + def task_factory(execute, **factory_kwargs): merged = kwargs.copy() merged.update(factory_kwargs) # NOTE(imelnikov): we can't capture f here because for # bound methods and bound class methods the object it # is bound to is yet unknown at the moment - return base.FunctorTask(execute_with, **merged) + return base.FunctorTask(execute, **merged) w_f = _original_function(f) setattr(w_f, utils.TASK_FACTORY_ATTRIBUTE, task_factory) return f diff --git a/taskflow/examples/complex_graph.py b/taskflow/examples/complex_graph.py index 9e66ef9f..0b47a622 100644 --- a/taskflow/examples/complex_graph.py +++ b/taskflow/examples/complex_graph.py @@ -95,7 +95,7 @@ def trash(context, result, cause): print("Throwing away pieces of car!") -@decorators.task(revert_with=trash) +@decorators.task(revert=trash) def startup(context, **kwargs): pass # TODO(harlowja): try triggering reversion here! diff --git a/taskflow/examples/reverting_linear.py b/taskflow/examples/reverting_linear.py index 4f58fde4..36164b5d 100644 --- a/taskflow/examples/reverting_linear.py +++ b/taskflow/examples/reverting_linear.py @@ -16,14 +16,14 @@ def undo_call(context, result, cause): print("Calling %s and apologizing." % result) -@decorators.task(revert_with=undo_call) +@decorators.task(revert=undo_call) def call_jim(context): print("Calling jim.") print("Context = %s" % (context)) return context['jim_number'] -@decorators.task(revert_with=undo_call) +@decorators.task(revert=undo_call) def call_joe(context): print("Calling joe.") print("Context = %s" % (context)) diff --git a/taskflow/task.py b/taskflow/task.py index 90e9c08d..aff4dfa3 100644 --- a/taskflow/task.py +++ b/taskflow/task.py @@ -99,42 +99,42 @@ class FunctorTask(BaseTask): Take any callable and make a task from it. """ - def __init__(self, execute_with, **kwargs): + def __init__(self, execute, **kwargs): """Initialize FunctorTask instance with given callable and kwargs - :param execute_with: the callable + :param execute: the callable :param kwargs: reserved keywords (all optional) are name: name of the task, default None (auto generate) - revert_with: the callable to revert, default None + revert: the callable to revert, default None version: version of the task, default Task's version 1.0 optionals: optionals of the task, default () provides: provides of the task, default () requires: requires of the task, default () - auto_extract: auto extract execute_with's args and put it into + auto_extract: auto extract execute's args and put it into requires, default True """ name = kwargs.pop('name', None) if name is None: - name = utils.get_callable_name(execute_with) + name = utils.get_callable_name(execute) super(FunctorTask, self).__init__(name) - self._execute_with = execute_with - self._revert_with = kwargs.pop('revert_with', None) + self._execute = execute + self._revert = kwargs.pop('revert', None) self.version = kwargs.pop('version', self.version) self.optional.update(kwargs.pop('optional', ())) self.provides.update(kwargs.pop('provides', ())) self.requires.update(kwargs.pop('requires', ())) if kwargs.pop('auto_extract', True): - f_args = utils.get_required_callable_args(execute_with) + f_args = utils.get_required_callable_args(execute) self.requires.update(a for a in f_args if a != 'context') if kwargs: raise TypeError('__init__() got an unexpected keyword argument %r' % kwargs.keys[0]) def __call__(self, *args, **kwargs): - return self._execute_with(*args, **kwargs) + return self._execute(*args, **kwargs) def revert(self, *args, **kwargs): - if self._revert_with: - return self._revert_with(*args, **kwargs) + if self._revert: + return self._revert(*args, **kwargs) else: return None diff --git a/taskflow/tests/unit/test_decorators.py b/taskflow/tests/unit/test_decorators.py index 193a6558..37f8e105 100644 --- a/taskflow/tests/unit/test_decorators.py +++ b/taskflow/tests/unit/test_decorators.py @@ -29,7 +29,7 @@ class WrapableObjectsTest(test.TestCase): def revert_one(*args, **kwargs): values.append('revert one') - @decorators.task(revert_with=revert_one) + @decorators.task(revert=revert_one) def run_one(*args, **kwargs): values.append('one') diff --git a/taskflow/tests/unit/test_functor_task.py b/taskflow/tests/unit/test_functor_task.py index 72a39aee..0e44308b 100644 --- a/taskflow/tests/unit/test_functor_task.py +++ b/taskflow/tests/unit/test_functor_task.py @@ -58,7 +58,7 @@ class FunctorTaskTest(test.TestCase): flow = linear_flow.Flow('test') flow.add_many(( - t(bof.run_one, revert_with=bof.revert_one), + t(bof.run_one, revert=bof.revert_one), t(bof.run_fail) )) with self.assertRaisesRegexp(RuntimeError, '^Woot'): diff --git a/taskflow/tests/unit/test_graph_flow.py b/taskflow/tests/unit/test_graph_flow.py index 639cfe8d..dd4e62ce 100644 --- a/taskflow/tests/unit/test_graph_flow.py +++ b/taskflow/tests/unit/test_graph_flow.py @@ -36,7 +36,7 @@ class GraphFlowTest(test.TestCase): self.assertEquals(states.REVERTING, cause.flow.state) self.assertEquals(result, {'a': 1}) - @decorators.task(revert_with=run1_revert, provides=['a']) + @decorators.task(revert=run1_revert, provides=['a']) def run1(context): # pylint: disable=W0613 return { 'a': 1, diff --git a/taskflow/tests/unit/test_linear_flow.py b/taskflow/tests/unit/test_linear_flow.py index b14f4d46..903d357f 100644 --- a/taskflow/tests/unit/test_linear_flow.py +++ b/taskflow/tests/unit/test_linear_flow.py @@ -39,7 +39,7 @@ class LinearFlowTest(test.TestCase): raise Exception("I blew up") return blow_up else: - @decorators.task(revert_with=do_revert, + @decorators.task(revert=do_revert, name='do_apply %s' % token) def do_apply(context, *args, **kwargs): context[token] = 'passed' diff --git a/taskflow/tests/unit/test_threaded_flow.py b/taskflow/tests/unit/test_threaded_flow.py index 7bcd85d0..65718006 100644 --- a/taskflow/tests/unit/test_threaded_flow.py +++ b/taskflow/tests/unit/test_threaded_flow.py @@ -318,7 +318,7 @@ class ThreadedFlowTest(test.TestCase): def reverter(context, result, cause): context['reverted'] = True - @decorators.task(revert_with=reverter) + @decorators.task(revert=reverter) def fail_quick(context): raise IOError("Broken")