def register_module(self, module, overwrite=False):
"""
Register all component classes within a module.
Parameters
----------
module : Union[str, `ModuleType`]
overwrite : bool
"""
if isinstance(module, basestring):
module = pydoc.locate(module)
if not inspect.ismodule(module):
raise ValueError('module must be either a module or the name of a '
'module')
self.logger.info('Registering components in module: {}'.format(
module.__name__))
registered = 0
for obj_name, class_obj in inspect.getmembers(module):
if (inspect.isclass(class_obj) and
class_obj is not Component and
not inspect.isabstract(class_obj) and
not issubclass(class_obj, SubGraph) and
issubclass(class_obj, Component)):
self.register_component(class_obj, overwrite)
registered += 1
if registered == 0:
self.logger.warn('No components were found in module: {}'.format(
module.__name__))
评论列表
文章目录