26 lines
1021 B
Python
26 lines
1021 B
Python
from inspect import isclass
|
|
from pkgutil import iter_modules
|
|
from pathlib import Path
|
|
from importlib import import_module
|
|
from raven.pluginbase import PluginBase
|
|
|
|
# iterate through the modules in the current package
|
|
from raven.pluginregistry import PluginRegistry
|
|
|
|
if False:
|
|
package_dir = Path(__file__).resolve().parent
|
|
for (_, module_name, _) in iter_modules([str(package_dir)]):
|
|
# import the module and iterate through its attributes
|
|
module = import_module(f"{__name__}.{module_name}")
|
|
print("module: %s" % module)
|
|
|
|
for attribute_name in dir(module):
|
|
if attribute_name == "PluginBase":
|
|
continue
|
|
attribute = getattr(module, attribute_name)
|
|
|
|
if isclass(attribute) and issubclass(attribute, PluginBase):
|
|
globals()[attribute_name] = attribute
|
|
PluginRegistry.register_plugin(attribute_name, attribute)
|
|
print("%s -> %s :: %s in %s" % (attribute_name, attribute, module_name, module))
|