Registration

class omnifig.registration.script(name=None, description=None, *, hidden=None)

Bases: _Project_Registration_Decorator

Decorator to register a script.

Scripts are callable objects (usually functions) with only one input argument (the config object) and can be called from the command line using the fig command.

__init__(name=None, description=None, *, hidden=None)
Parameters:
  • name (Optional[str]) – name of item to be registered (defaults to its __name__)

  • description (Optional[str]) – a short description of what the script does (defaults to first line of its docstring)

  • hidden (bool) – if True, the script will not be listed in the help menu

static register_project(project, name, item, description=None, hidden=None, **kwargs)

Must be implemented by subclasses to register the item with the current project

Return type:

None

class omnifig.registration.creator(name=None, description=None)

Bases: _Project_Registration_Decorator

Decorator to register a creator.

Creators are generally subclasses of AbstractCreator and are used to create objects from the config.

Usually, the default creator is sufficient, but this decorator can be used to register a custom creator.

__init__(name=None, description=None)
Parameters:
  • name (Optional[str]) – name of item to be registered (defaults to its __name__)

  • description (Optional[str]) – a short description of what the script does (defaults to first line of its docstring)

static register_project(project, name, item, description=None, **kwargs)

Must be implemented by subclasses to register the item with the current project

Return type:

None

class omnifig.registration.component(name=None, description=None, creator=None)

Bases: _Project_Registration_Decorator

Decorator to register a component.

Components are (usually) classes, and can be automatically be instantiated from the config object (using the _type key).

There are generally two different ways to use components. Both use a creator (see AbstractCreator):
  1. If the component is a subclass of Configurable,

    arguments in __init__ can be automatically be filled in with the config object.

  2. Otherwise, the component will be instantiated (by default) with the following signature:

    config, *args, **kwargs, where config is the config object, while *args and **kwargs are arguments manually passed to the creator. This is the signature expected for init_from_config() if the component is a subclass of AbstractConfigurable and __init__() otherwise.

__init__(name=None, description=None, creator=None)

Decorator to register a component.

Parameters:
  • name (Optional[str]) – name of item to be registered (defaults to its __name__)

  • description (Optional[str]) – a short description of what the script does (defaults to first line of its docstring)

  • creator (Optional[str]) – name of the creator that should be used to create this component (generally not recommended)

static register_project(project, name, item, description=None, creator=None, **kwargs)

Must be implemented by subclasses to register the item with the current project

Return type:

None

class omnifig.registration.modifier(name=None, description=None)

Bases: _Project_Registration_Decorator

Decorator to register a modifier.

Modifiers are “runtime mixins” for components and must be classes. When specifying a component to be modified with the _mod key in the config, a new type is dynamically created for which the bases are all the specified modifiers followed by the original component.

__init__(name=None, description=None)

Decorator to register a modifier.

Parameters:
  • name (Optional[str]) – name of item to be registered (defaults to its __name__)

  • description (Optional[str]) – a short description of what the script does (defaults to first line of its docstring)

static register_project(project, name, item, description=None, **kwargs)

Must be implemented by subclasses to register the item with the current project

Return type:

None

class omnifig.registration.autoscript(name=None, description=None, aliases=None, **kwargs)

Bases: _AutofillMixin, script

Convienence decorator to register scripts where the arguments of the script signature are automatically extracted from the config before running the script.

Note

This is generally only recommended for simple, short scripts (since it severely limits the usage of the config object by the script).

__init__(name=None, description=None, aliases=None, **kwargs)

Decorator to register a script (where arguments are extracted from the config automatically).

Parameters:
  • name (Optional[str]) – name of item to be registered (defaults to its __name__)

  • description (Optional[str]) – a short description of what the script does (defaults to first line of its docstring)

  • aliases (Optional[Dict[str, Union[str, Sequence[str]]]]) – alternative names for arguments (can have multiple aliases per argument)

class omnifig.registration.autocomponent(name=None, description=None, aliases=None, creator=None)

Bases: _AutofillMixin, component

Convienence decorator to register components where the arguments of the component function are automatically extracted from the config

Note

This is generally only recommended for simple components that are functions (rather than classes), since class components should simply subclass Configurable for effectively the same behavior.

__init__(name=None, description=None, aliases=None, creator=None)

Decorator to register a component (where arguments are extracted from the config automatically).

Parameters:
  • name (Optional[str]) – name of item to be registered (defaults to its __name__)

  • description (Optional[str]) – a short description of what the script does (defaults to first line of its docstring)

  • aliases (Optional[Dict[str, Union[str, Sequence[str]]]]) – alternative names for arguments (can have multiple aliases per argument)

  • creator (Union[str, AbstractCreator, None]) – name of the creator that should be used to create this component