Tamahagane

Forge your application registries.

class tamahagane.Scanner(registry: T)

Scan python modules, collect hooks, then callback.

classmethod attach(wrapped: Callable[[...], Any], callback: Callable[[T], None], category: str) None

Attach method from the scanner.

This is a more verbose way to attach a callback, with better typing support.

collected_hooks: ClassVar[dict[str, list[CallbackInfo]]] = {}
classmethod load_modules(*modules: ModuleType, ignore: Sequence[str] = ()) None
loaded_mods: ClassVar[set[ModuleType]] = {}
scan(*modules: ModuleType | str, stack_depth: int = 1, ignore: Sequence[str] = ()) None

Scan modules from the given parameter.

Parameters:
  • modules – modules are absolute or relative if the starts with a dot.

  • stack_depth – in case of relative package, speficy from what the package is relative too. If you expose a scan method in a framework, the depth of the stack frame must be updated in order to get it relative to the appropriate caller.

registry: T
tamahagane.attach(wrapped: Callable[[...], Any], callback: Callable[[Any], None], category: str) None

Attach a callback to a category while loading a module.

This function preload the callback, arranged by their category.

Parameters:
  • wrapped – the wrapped function that will be added to a regitry during the scan.

  • callback – the callback to call when the scan is called.

  • category – an attribute of the registry, if the registry does not have an attribute that matche the category, the category will callback will never be loaded.