core.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:phat 作者: danielfranca 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号