executor¶
-
class
invoke.executor.Executor(collection, config=None, core=None)¶ An execution strategy for Task objects.
Subclasses may override various extension points to change, add or remove behavior.
-
__init__(collection, config=None, core=None)¶ Initialize executor with handles to necessary data structures.
Parameters: - collection – A
Collectionused to look up requested tasks (and their default config data, if any) by name during execution. - config – An optional
Configholding configuration state. Defaults to an emptyConfigif not given. - core –
An optional
ParserContextholding core program arguments. Defaults toNone.Note
This is unused by the default implementation, but may be useful to subclasses which care about specific core arguments re: execution strategy, use of the parse remainder, etc.
- collection – A
-
__weakref__¶ list of weak references to the object (if defined)
-
dedupe(calls)¶ Deduplicate a list of
tasks.Parameters: calls – An iterable of Callobjects representing tasks.Returns: A list of Callobjects.
-
execute(*tasks)¶ Execute one or more
tasksin sequence.Parameters: tasks – An all-purpose iterable of “tasks to execute”, each member of which may take one of the following forms:
A string naming a task from the Executor’s
Collection. This name may contain dotted syntax appropriate for calling namespaced tasks, e.g.subcollection.taskname. Such tasks are executed without arguments.A two-tuple whose first element is a task name string (as above) and whose second element is a dict suitable for use as
**kwargswhen calling the named task. E.g.:[ ('task1', {}), ('task2', {'arg1': 'val1'}), ... ]
is equivalent, roughly, to:
task1() task2(arg1='val1')
A `.ParserContext` instance, whose
.nameattribute is used as the task name and whose.as_kwargsattribute is used as the task kwargs (again following the above specifications).Note
When called without any arguments at all (i.e. when
*tasksis empty), the default task fromself.collectionis used instead, if defined.Returns: A dict mapping task objects to their return values. This dict may include pre- and post-tasks if any were executed. For example, in a collection with a
buildtask depending on another task namedsetup, executingbuildwill result in a dict with two keys, one forbuildand one forsetup.
-
expand_calls(calls)¶ Expand a list of
Callobjects into a near-final list of same.The default implementation of this method simply adds a task’s pre/post-task list before/after the task itself, as necessary.
Subclasses may wish to do other things in addition (or instead of) the above, such as multiplying the
callsby argument vectors or similar.
-