__init__.py 1023 B

1234567891011121314151617181920212223242526272829
  1. from loguru import logger
  2. from aphrodite import envs
  3. def load_general_plugins():
  4. """WARNING: plugins can be loaded for multiple times in different
  5. processes. They should be designed in a way that they can be loaded
  6. multiple times without causing issues.
  7. """
  8. import sys
  9. if sys.version_info < (3, 10):
  10. from importlib_metadata import entry_points
  11. else:
  12. from importlib.metadata import entry_points
  13. allowed_plugins = envs.APHRODITE_PLUGINS
  14. discovered_plugins = entry_points(group='aphrodite.general_plugins')
  15. for plugin in discovered_plugins:
  16. logger.info(f"Found general plugin: {plugin.name}")
  17. if allowed_plugins is None or plugin.name in allowed_plugins:
  18. try:
  19. func = plugin.load()
  20. func()
  21. logger.info(f"Loaded general plugin: {plugin.name}")
  22. except Exception:
  23. logger.exception("Failed to load general plugin: "
  24. f"{plugin.name}")