def load_classes(kind: str):
import pkgutil
import importlib
paths = []
paths.append(os.path.join(os.path.dirname(__file__), "..", "plugins"))
extra_path = os.getenv('PHAT_EXTRA_PLUGINS_DIR')
if extra_path:
extra_path = os.path.join(extra_path, "plugins")
paths.append(extra_path)
for path in paths:
if path not in sys.path:
sys.path.append(path)
logger.debug("Loading {}s from {}: ".format(kind, paths))
loaded_items = []
for _, name, ispkg in pkgutil.walk_packages(path=paths):
logger.debug("Loading {}: {}".format(kind, name))
if ispkg:
try:
module = importlib.import_module('{}.{}'.format(name, kind))
except ImportError as ex:
logger.debug("Error importing module: {0} of kind: {1}".format(name, kind))
else:
loaded_items.append(module)
# TODO: Return the classes instead of modules
return loaded_items
评论列表
文章目录