Task

class spype.core.task.Forward[source]

A task for simply forwarding inputs to the next task.

class spype.core.task.PypeInput[source]

A singleton Task that is used, explicitly or implicitly, to begin each pype.

class spype.core.task.Task[source]

An abstract class whose subclasses encapsulate a unit of work.

copy()[source]

Return a deep copy of task.

Return type:Task
get_name()[source]

Return the name of task.

Return type:str
get_option(option)[source]

Returns an option defined in self or defer to Task MRO.

Parameters:option (str) – A supported Spype option. See spype.options.
Return type:Any
get_signature()[source]

return signature of bound run method

Return type:Signature
run(*args, _fixtures=None, _callbacks=None, _predicate=None, **kwargs)[source]

Call the task’s __call__ and handle spype magic in the background.

Run essentially performs the following steps:
  1. Try to bind args and kwawrgs to the task signature
  2. If bind raises, look for missing arguments in _fixtures
  3. Rebind args and kwargs to signature with new args if needed
  4. Run on_start callback, if defined
  5. Run task call method (or function)
  6. Run on_failure callback if defined and an exception was raised
  7. Run on_success callback if defined and no exception was raised
  8. Run on_finish callback, if defined
  9. Return output of call method, or output of any callback if any non-None values were returned.
Parameters:
  • _fixtures (Optional[Mapping[str, Any]]) – A dict of fixtures. Keys are parameters that might be used by callbacks and values are the values to substitute.
  • _callbacks (Optional[Mapping[str, Union[Callable, Sequence[Callable]]]]) – A dict of callbacks. Keys must be supported callback names (str) and values must be callables.
  • _predicate (Union[Callable[…, bool], Sequence[Callable[…, bool]], None]) – A single function, or sequence of functions, that return a bool. Standard fixtures can be used, just like in callbacks.
validate_callback(callback)[source]

Raise TypeError if callback is not a valid callback for this task.

Parameters:callback (Callable) – Any callable
Return type:None
validate_callbacks()[source]

Iterate over all attached callbacks and raise TypeError if any problems are detected.

Return type:None
wrap(*args, **kwargs)[source]

Instantiate a Wrap instance from this task.

Args and kwargs are passed to Wrap constructor.

Returns:
Return type:Wrap
spype.core.task.task(func=None, *, on_start=None, on_failure=None, on_success=None, on_finish=None, predicate=None, **kwargs)[source]

Decorator for registering a callable as a tasks.

This essentially adds the Task class attributes to a function and returns the function. This means the function will behave as before, but will have the Task class attributes attached. This approach is needed so that the tasks are pickable, else returning Task instances would work.

Parameters:
  • func (Optional[Callable]) – A callable to use as a task
  • on_start (Union[Callable, Sequence[Callable], None]) – Callable which is called before running task
  • on_failure (Union[Callable, Sequence[Callable], None]) – Callable which will be called when a task fails
  • on_success (Union[Callable, Sequence[Callable], None]) – Callable that gets called when a task succeeds
  • on_finish (Union[Callable, Sequence[Callable], None]) – Callable that gets called whenever a task finishes
Returns:

An instance of Task

Return type:

Task