diff --git a/comictalker/__init__.py b/comictalker/__init__.py index e5bd095..e216f27 100644 --- a/comictalker/__init__.py +++ b/comictalker/__init__.py @@ -2,8 +2,13 @@ from __future__ import annotations import logging import pathlib +import sys + +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points -import comictalker.talkers.comicvine from comictalker.comictalker import ComicTalker, TalkerError from comictalker.resulttypes import ComicIssue, ComicSeries @@ -21,11 +26,13 @@ def get_talkers(version: str, cache: pathlib.Path) -> dict[str, ComicTalker]: """Returns all comic talker instances""" talkers: dict[str, ComicTalker] = {} - for talker in [comictalker.talkers.comicvine.ComicVineTalker]: + for talker in entry_points(group="comictagger.talkers"): try: - obj = talker(version, cache) + talker_cls = talker.load() + obj = talker_cls(version, cache) talkers[obj.id] = obj except Exception: - logger.exception("Failed to load talker: %s", "comicvine") - raise TalkerError(source="comicvine", code=4, desc="Failed to initialise talker") + logger.exception("Failed to load talker: %s", talker.name) + raise TalkerError(source=talker.name, code=4, desc="Failed to initialise talker") + return talkers diff --git a/setup.py b/setup.py index 291d1bc..d234566 100644 --- a/setup.py +++ b/setup.py @@ -66,6 +66,9 @@ setup( "rar = comicapi.archivers.rar:RarArchiver", "folder = comicapi.archivers.folder:FolderArchiver", ], + "comictagger.talkers": [ + "comicvine = comictalker.talkers.comicvine:ComicVineTalker", + ], }, classifiers=[ "Development Status :: 4 - Beta",