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
managersobject 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.ManagerNotFoundexception
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
Hooksubclass. If you try to access a hook from a manager that does not contain any hooks, Socon will raise aManagerNotHookedexception.
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
labelthat 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:
- Did the user pass a config object?
Yes, search the hook for that config. It is found return it else continue.
- Search in the common space config for hooks.
If it’s found return it else continue.
- Search in the plugins.
If it’s found return it else continue.
- Search in built-in Socon hooks.
if it’s found return it else continue.
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
Nonewhen being registered, Socon will raise anImproperlyConfiguredexception.