Merge branch 'mizaki/talkers_version_check' into develop

This commit is contained in:
Timmy Welch 2023-12-13 09:52:20 -08:00
commit 3c83dbd038
2 changed files with 18 additions and 1 deletions

View File

@ -4,6 +4,8 @@ import logging
import pathlib
import sys
from packaging.version import InvalidVersion, parse
if sys.version_info < (3, 10):
from importlib_metadata import entry_points
else:
@ -22,6 +24,7 @@ __all__ = [
def get_talkers(version: str, cache: pathlib.Path) -> dict[str, ComicTalker]:
"""Returns all comic talker instances"""
talkers: dict[str, ComicTalker] = {}
ct_version = parse(version)
for talker in entry_points(group="comictagger.talker"):
try:
@ -30,7 +33,20 @@ def get_talkers(version: str, cache: pathlib.Path) -> dict[str, ComicTalker]:
if obj.id != talker.name:
logger.error("Talker ID must be the same as the entry point name")
continue
talkers[talker.name] = obj
try:
if ct_version >= parse(obj.comictagger_min_ver):
talkers[talker.name] = obj
else:
logger.error(
f"Minimum ComicTagger version required of {obj.comictagger_min_ver} for talker {talker.name} is not met, will NOT load talker"
)
except InvalidVersion:
logger.warning(
f"Invalid minimum required ComicTagger version number for talker: {talker.name} - version: {obj.comictagger_min_ver}, will load talker anyway"
)
# Attempt to use the talker anyway
# TODO flag this problem for later display to the user
talkers[talker.name] = obj
except Exception:
logger.exception("Failed to load talker: %s", talker.name)

View File

@ -107,6 +107,7 @@ class ComicTalker:
name: str = "Example"
id: str = "example"
comictagger_min_ver: str = "1.6.0a7" # The ComicTagger minimum version required by the talker
website: str = "https://example.com"
logo_url: str = f"{website}/logo.png"
attribution: str = f"Metadata provided by <a href='{website}'>{name}</a>"