Manager

This document references the base class for managers and hooks. For information on how to use them and how to write your own managers and hooks, see custom managers and hooks. You can also find a tutorial about managers and hooks here.

Manager Registry

class ManagerRegistry[source]

Base class that stores all the managers. At the start Socon creates a managers object that is accessible like this:

from socon.core.manager import managers

Use this at all time when you want to access a manager.

Methods

ManagerRegistry.get_manager(name: str)[source]

Return the manager with the given name or raise a socon.core.exceptions.ManagerNotFound exception

ManagerRegistry.get_managers()[source]

Return all registered managers.

Manager objects

class BaseManager[source]

The base class from which all managers will derive from.

By subclassing your class from the BaseManager and by explicitly placing your class into managers.py in a plugin, project or in the common config will auto-register the class as a manager.

When a manager is defined, it requires to be hooked to Hook subclass. If you try to access a hook from a manager that does not contain any hooks, Socon will raise a ManagerNotHooked exception.

Read-only attributes

BaseManager.hooks

A dictionary of all hooks registered by registry name and config registry label.

Configurable attributes

BaseManager.name

Name of the manager. This class attribute is mandatory.

BaseManager.lookup_module

Name of the module the manager will into to import hooks.

Methods

BaseManager.get_modules(config: Type[:class:`RegistryConfig`])[source]

Return a list of modules to be imported by the manager. It’s in that list that all the hooks of this manager must be define.

BaseManager.find_all()[source]

Look into each installed registry config for hooks. This method import all modules returned by BaseManager.get_modules(). When a module is imported, it auto-register every hook in that module.

BaseManager.find_hooks_impl(config: Type[:class:`RegistryConfig`])[source]

Look into a specific registry config for hooks. This method import all modules return by BaseManager.get_modules() for that specific config.

BaseManager.get_hook(config: Type[:class:`RegistryConfig`], name: str)[source]

Return a hook for a specific registry config. If the hook is not found, the method will return None.

BaseManager.get_hooks(config: Type[:class:`RegistryConfig`])[source]

Find all hooks associated to a registry config. This method returns an empty list or a list of hooks.

BaseManager.get_hook_config_holders(name: str)[source]

Return a list of registry config label that hold a specific hook.

BaseManager.search_hook_impl(name, config: Type[:class:`RegistryConfig`]=None)[source]

Search for a hook globally or for a specific registry config. The search is done following a specific order:

  1. Did the user pass a config object?

    Yes, search the hook for that config. It is found return it else continue.

  2. Search in the common space config for hooks.

    If it’s found return it else continue.

  3. Search in the plugins.

    If it’s found return it else continue.

  4. Search in built-in Socon hooks.

    if it’s found return it else continue.

  5. Raise socon.core.exceptions.HookNotFound.

BaseManager.get_hooks_name()[source]

Return a list of all registered hooks name

Hooks objects

class Hook[source]

The base class from which all hooks will derive from. Every class that derive from this class, must define a manager.

Configurable attributes

Hook.manager

The manager the hook class will be linked to. If this attribute is None when being registered, Socon will raise an ImproperlyConfigured exception.