ucsschool.lib.pyhooks package

Python based hooks.


ucsschool.lib.pyhooks.pyhook module

Base class for all Python based hooks.

class ucsschool.lib.pyhooks.pyhook.PyHook(*arg, **kwargs)[source]

Bases: object

Base class for all Python based hooks.

Do not use this class directly, use one of its subclasses like UserPyHook.

priority = {}

ucsschool.lib.pyhooks.pyhooks_loader module

Loader for Python based hooks.

class ucsschool.lib.pyhooks.pyhooks_loader.PyHooksLoader(base_dir, base_class, logger=None, filter_func=None)[source]

Bases: object

Loader for PyHooks.

Use get_hook_objects() to get initialized and sorted objects. Use get_hook_classes() if you want to initialize them yourself.

Hint: if you wish to pass a logging instance to a hook, add it to the arguments list of get_hook_objects() and receive it in the hooks __init__() method.

If filter_func is a callable, it will be passed each class that is considered for loading and it can decide if it should be loaded or not. Thus its signature is (type) -> bool.

  • base_dir (str) – path to a directory containing Python files
  • base_class (type) – only subclasses of this class will be imported
  • logger (logging.Logger) – Python logging instance to use for loader logging (deprecated, ignored)
  • filter_func (Callable) – function that takes a class and returns a bool
_hook_classes = {}

Drop the cache of loaded hook classes and force a rerun of the filesystem search, next time get_hook_classes() or get_pyhook_objects() is called.


Search hook files in filesystem and load classes. No objects are initialized, no sorting is done.

Returns:list of PyHook subclasses
Return type:list[type]
get_hook_objects(*args, **kwargs)[source]

Get initialized hook objects, sorted by method and priority.

  • args (tuple) – arguments to pass to __init__ of hooks
  • kwargs (dict) – arguments to pass to __init__ of hooks

mapping from method names to list of methods of initialized hook objects, sorted by method priority

Return type:

Dict[str, List[Callable]]

static _load_hook_class(cls_name, info, super_class)[source]