tamahagane.scanner¶
tamahagene scanner implementation
Module Contents¶
Classes¶
Store information at import time to fillout registries during the scan. |
|
Scan python modules, collect hooks, then callback. |
Functions¶
Attach a callback to a category while loading a module. |
Data¶
Represent the final registry to forge. |
|
Represent a valid attribute of the registry T. |
|
Callback hook. |
|
Represent the decorated method that will be hooked in the registry after a scan. |
API¶
- tamahagane.scanner.T¶
‘TypeVar(…)’
Represent the final registry to forge.
- tamahagane.scanner.KeyOfRegistry¶
None
Represent a valid attribute of the registry T.
- tamahagane.scanner.CallbackHook¶
None
Callback hook.
- tamahagane.scanner.RegisteredFn¶
None
Represent the decorated method that will be hooked in the registry after a scan.
- class tamahagane.scanner.CallbackInfo¶
Store information at import time to fillout registries during the scan.
- fn: tamahagane.scanner.RegisteredFn¶
None
The decorated method.
- callback: tamahagane.scanner.CallbackHook[Any]¶
None
Its inner callback method.
- class tamahagane.scanner.Scanner(registry: tamahagane.scanner.T)¶
Bases:
typing.Generic[tamahagane.scanner.T]Scan python modules, collect hooks, then callback.
Initialization
Initialize the scanner for the given registry.
- Parameters:
registry – application registry contains attributes of registry to scan. The attributes act as the category to filters at scanning.
- scan(*modules: types.ModuleType | str, stack_depth: int = 1, ignore: collections.abc.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.
- classmethod attach(wrapped: tamahagane.scanner.RegisteredFn, callback: tamahagane.scanner.CallbackHook[tamahagane.scanner.T], category: tamahagane.scanner.KeyOfRegistry) None¶
Attach method from the scanner.
This is a more verbose way to attach a callback, with better typing support.
- tamahagane.scanner.attach(wrapped: tamahagane.scanner.RegisteredFn, callback: tamahagane.scanner.CallbackHook[Any], category: tamahagane.scanner.KeyOfRegistry) 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.