decorators#

Custom law task method decorators.

Functions:

only_local_env(fn, opts, task, *args, **kwargs)

A decorator that ensures that the task's decorated method is only executed in the local environment, and not by (e.g.) remote jobs.

on_failure(fn, opts, task, *args, **kwargs)

callback(callback=None) A decorator that is configured with a callback function that is invoked if the decorated method raises an exception.

view_output_plots(fn, opts, task, *args, ...)

This decorator is used to view the output plots of a task.

only_local_env(fn, opts, task, *args, **kwargs)[source]#

A decorator that ensures that the task’s decorated method is only executed in the local environment, and not by (e.g.) remote jobs.

Parameters:
  • fn (Callable) – The decorated function.

  • opts (Any) – Options for the decorator.

  • task (Task) – The task instance.

  • args (Any) – Arguments to be passed to the function call.

  • kwargs (Any) – Keyword arguments to be passed to the function call.

Return type:

tuple[Callable, Callable, Callable]

Returns:

A tuple containing the before_call, call, and after_call functions.

on_failure(fn, opts, task, *args, **kwargs)[source]#

callback(callback=None) A decorator that is configured with a callback function that is invoked if the decorated method raises an exception. The task instances is passed to the callback function as an argument.

Parameters:
  • fn (Callable) – The decorated function.

  • opts (Any) – Options for the decorator.

  • task (Task) – The task instance.

  • args (Any) – Arguments to be passed to the function call.

  • kwargs (Any) – Keyword arguments to be passed to the function call.

Return type:

tuple[Callable, Callable, Callable]

Returns:

A tuple containing the before_call, call, and after_call functions.

view_output_plots(fn, opts, task, *args, **kwargs)[source]#

This decorator is used to view the output plots of a task. It checks if the task has a view command, collects all the paths of the output files, and then opens each file using the view command.

Parameters:
  • fn (Callable) – The decorated function.

  • opts (Any) – Options for the decorator.

  • task (Task) – The task instance.

  • args (Any) – Arguments to be passed to the function call.

  • kwargs (Any) – Keyword arguments to be passed to the function call.

Return type:

tuple[Callable, Callable, Callable]

Returns:

A tuple containing the before_call, call, and after_call functions.