robokudo.utils.decorators

Decorator utilities for RoboKudo annotators.

This module provides decorators to extend annotator functionality.

module:

decorators

synopsis:

Decorator utilities for RoboKudo annotators

moduleauthor:

RoboKudo Team

Dependencies:
  • timeit

  • collections.defaultdict

  • robokudo.annotators.core

Functions:

Functions

timer_decorator(...)

Log execution time of decorated function.

record_time(→ typing_extensions.Callable[[Ellipsis], ...)

Record execution time of annotator method.

publish_variables(...)

Publish annotator variables after method execution.

Module Contents

robokudo.utils.decorators.timer_decorator(func: typing_extensions.Callable[[Ellipsis], typing_extensions.Any]) typing_extensions.Callable[[Ellipsis], typing_extensions.Any]

Log execution time of decorated function.

Parameters:

func – Function to be timed

Returns:

Wrapped function that logs execution time

Example:

@timer_decorator
def my_function():
    # Function code here
    pass

Note

Uses rk_logger if available, otherwise prints to stdout

robokudo.utils.decorators.record_time(func: typing_extensions.Callable[[Ellipsis], typing_extensions.Any]) typing_extensions.Callable[[Ellipsis], typing_extensions.Any]

Record execution time of annotator method.

Parameters:

func – Annotator method to time

Returns:

Wrapped method that records execution time

Example:

@record_time
def compute(self):
    # Method code here
    pass

Note

Only works on annotator instance methods

robokudo.utils.decorators.publish_variables(func: typing_extensions.Callable[[Ellipsis], typing_extensions.Any]) typing_extensions.Callable[[Ellipsis], typing_extensions.Any]

Publish annotator variables after method execution.

Parameters:

func – Annotator method to wrap

Returns:

Wrapped method that publishes variables

Raises:

AssertionError – If not used on BaseAnnotator instance method

Example:

@publish_variables
def update(self):
    # Method code here
    pass

Note

Only works on BaseAnnotator instance methods