Skip to content

daemon_loader

Core logic to:
(1) scan external Python scripts requested by CLI users when interacting with daemons,
(2) collect all classes inheriting from Daemon or UNIXDaemon base classes
(3) Instantiate one object per class found to start these daemons when CLI users request it

Functions:

find_daemon_classes

find_daemon_classes(module: ModuleType | None = None, strict: bool = True) -> List[Type]

Function to scan input module and collect + return a list of specific daemon classes.
Module scan is performed using the inspect module (docs: https://docs.python.org/3/library/inspect.html)

Parameters:

  • module

    (ModuleType | None, default: None ) –

    Input module

  • strict

    (bool, default: True ) –

    Return only (True) the classes from the script itself (not those imported to the script from other sub-modules/dependencies)

Returns:

  • List[Type]

    List of daemon classes

get_daemon_instances

get_daemon_instances(daemons: List[Type] | None = None, only_includes: Dict[str, str] | None = None, script_path: Path | None = None) -> List[Any]

Function to get daemon instances from daemon classes

Parameters:

  • daemons

    (List[Type] | None, default: None ) –

    Input daemon classes

  • only_includes

    (Dict[str, str] | None, default: None ) –

    Dict of daemon classes (and daemon names) to be included only if found in the module (by func fun: find_daemon_classes)

  • script_path

    (Path | None, default: None ) –

    Input script path (used to get a default daemon name in case a given daemon class (from CLI input) does not have a respective daemon name

Returns:

  • List[Any]

    List of daemon objects (1 y input daemon class)

load_module_from_script

load_module_from_script(script_path: Path | str | None = None) -> ModuleType | None

Function to load a specific module from a given input Python script.
This function is using importlib (docs: https://docs.python.org/3/library/importlib.html)
and pathlib (docs: https://docs.python.org/3/library/pathlib.html).

Parameters:

  • script_path

    (Path | str | None, default: None ) –

    Input script path

Returns:

  • ModuleType | None

    Module object imported via importlib.util if successful, None otherwise