comparison libervia/backend/core/main.py @ 4281:9e63e02318ec

core: show warning instead of exception in case of missing dependency when loading plugins
author Goffi <goffi@goffi.org>
date Fri, 12 Jul 2024 18:53:00 +0200
parents 0d7bb4df2343
children 3a550e9a2b55
comparison
equal deleted inserted replaced
4280:4cf98f506269 4281:9e63e02318ec
382 ) 382 )
383 continue 383 continue
384 plugin_path = f"libervia.backend.plugins.{plug_name}" 384 plugin_path = f"libervia.backend.plugins.{plug_name}"
385 try: 385 try:
386 __import__(plugin_path) 386 __import__(plugin_path)
387 except exceptions.MissingModule as e: 387 except (ModuleNotFoundError, exceptions.MissingModule) as e:
388 self._unimport_plugin(plugin_path) 388 self._unimport_plugin(plugin_path)
389 log.warning( 389 log.warning(
390 "Can't import plugin [{path}] because of an unavailale third party " 390 "Can't import plugin [{path}] because of an unavailale third party "
391 "module:\n{msg}".format(path=plugin_path, msg=e) 391 "module:\n{msg}".format(path=plugin_path, msg=e)
392 ) 392 )
501 raise e 501 raise e
502 log.info("importing plugin: {}".format(plugin_info["name"])) 502 log.info("importing plugin: {}".format(plugin_info["name"]))
503 # we instanciate the plugin here 503 # we instanciate the plugin here
504 try: 504 try:
505 self.plugins[import_name] = getattr(mod, plugin_info["main"])(self) 505 self.plugins[import_name] = getattr(mod, plugin_info["main"])(self)
506 except Exception as e: 506 except (exceptions.NotFound, Exception) as e:
507 log.exception( 507 if isinstance(e, exceptions.NotFound):
508 f"Can't load plugin \"{plugin_info['name']}\", ignoring it: {e}" 508 # A warning is enough for a missing dependency.
509 ) 509 log.warning(
510 f"Can't load plugin \"{plugin_info['name']}\", due to missing "
511 f"dependency, ignoring it: {e}"
512 )
513 else:
514 log.exception(
515 f"Can't load plugin \"{plugin_info['name']}\", ignoring it"
516 )
510 if optional: 517 if optional:
511 return 518 return
512 raise ImportError("Error during initiation") 519 raise ImportError("Error during initiation")
513 if C.bool(plugin_info.get(C.PI_HANDLER, C.BOOL_FALSE)): 520 if C.bool(plugin_info.get(C.PI_HANDLER, C.BOOL_FALSE)):
514 self.plugins[import_name].is_handler = True 521 self.plugins[import_name].is_handler = True