auto_process_ngs.decorators

Implements decorators for use with the AutoProcessor class.

auto_process_ngs.decorators.add_command(name, f)

Add a method to an AutoProcessor class

Implements an @add_command’ decorator which can be used to add a function to an AutoProcessor class as a new method (aka ‘command’).

When the method is invoked additional output is added to report the run ID and the command name, and to mark the start and end of the command execution.

Additionally the command execution is wrapped in a try/except block.

For example:

>>> def hello(cls):
...    print("Hello %s" % cls.person)
...
>>> @command("greeting",hello)
... class Example:
...   def __init__(self):
...      self.person = "World"
...   def __str__(self):
...      return "Example: '%s'" % self.person
...
>>> Example().greeting()
[2023-01-11 09:36:04] Example: 'World'
[2023-01-11 09:36:04] Running 'greeting' command
Hello World
[2023-01-11 09:36:04] greeting: finished

The function must accept a class instance as the first argument.

Parameters:
  • name (str) – name of the command (which will be the method name when added)

  • f (object) – callable object (e.g. function) that will be invoked by the command. The first argument of the callable must be an AutoProcessor-like class