ucsschool.lib.pyhooks package#

Python based hooks.

Submodules#

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: str, base_class: str | Type[PyHookTV], logger: logging.Logger | None = None, filter_func: Callable[[Type[PyHookTV]], bool] | None = 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.

Parameters:
  • base_dir (str) – path to a directory containing Python files

  • base_class (str or type) – only subclasses of this class will be imported. This can be either a class object or the fully dotted Python path to a class (the latter helps to prevent import loops).

  • 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

drop_cache() None[source]#

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.

Returns:

None

get_hook_classes() List[Type[PyHookTV]][source]#

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: Any, **kwargs: Any) Dict[str, List[Callable[[...], Any]]][source]#

Get initialized hook objects, sorted by method and priority.

Parameters:
  • args (tuple) – arguments to pass to __init__ of hooks

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

Returns:

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

Return type:

Dict[str, List[Callable]]

static hook_cls2importpyhook(hook_cls_arg: Type[PyHookTV] | str, arg_name: str) Type[PyHookTV][source]#