Helper functions to search for implementations of specific abstract interface in a package.
- patroni.dynamic_loader. find_class_in_module ( module : ModuleType , cls_type : Type [ ClassType ] ) Type [ ClassType ] | None View on GitHub
-
Try to find the implementation of cls_type class interface in module matching the module name.
- Parameters :
-
-
module – imported module.
-
cls_type – a class type we are looking for.
-
- Returns :
-
class with a name matching the name of module that implements cls_type or
None
if not found.
- patroni.dynamic_loader. iter_classes ( package : str , cls_type : Type [ ClassType ] , config : Config | Dict [ str , Any ] | None = None ) Iterator [ Tuple [ str , Type [ ClassType ] ] ] View on GitHub
-
Attempt to import modules and find implementations of cls_type that are present in the given configuration.
Note
If a module successfully imports we can assume that all its requirements are installed.
- Parameters :
-
-
package – a package name to search modules in, e.g.
patroni.dcs
. -
cls_type – a class type we are looking for.
-
config – configuration information with possible module names as keys. If given, only attempt to import modules defined in the configuration. Else, if
None
, attempt to import any supported module.
-
- Yields :
-
a tuple containing the module
name
and the imported class object.
- patroni.dynamic_loader. iter_modules ( package : str ) List [ str ] View on GitHub
-
Get names of modules from package , depending on execution environment.
Note
If being packaged with PyInstaller, modules aren’t discoverable dynamically by scanning source directory because
importlib.machinery.FrozenImporter
doesn’t implementiter_modules()
. But it is still possible to find all potential modules by iterating throughtoc
, which contains list of all "frozen" resources.- Parameters :
-
package – a package name to search modules in, e.g.
patroni.dcs
. - Returns :
-
list of known module names with absolute python module path namespace, e.g.
patroni.dcs.etcd
.