From 12dd06c55824cc2201cd11b83255b4e389e74468 Mon Sep 17 00:00:00 2001 From: Mizaki Date: Thu, 30 Nov 2023 01:50:28 +0000 Subject: [PATCH] Add CT verion check against talker requirements --- comictalker/__init__.py | 12 +++++++++++- comictalker/comictalker.py | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/comictalker/__init__.py b/comictalker/__init__.py index 6788fa4..08a7fd1 100644 --- a/comictalker/__init__.py +++ b/comictalker/__init__.py @@ -4,6 +4,8 @@ import logging import pathlib import sys +from packaging.specifiers import InvalidSpecifier, SpecifierSet + if sys.version_info < (3, 10): from importlib_metadata import entry_points else: @@ -30,7 +32,15 @@ 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 version in SpecifierSet(obj.ct_req_spec, prereleases=True): + talkers[talker.name] = obj + else: + logger.error( + f"CT required version not met for talker: {talker.name} with specifier: {obj.ct_req_spec}" + ) + except InvalidSpecifier: + logger.error(f"Invalid specifier for talker: {talker.name} - specifier: {obj.ct_req_spec}") except Exception: logger.exception("Failed to load talker: %s", talker.name) diff --git a/comictalker/comictalker.py b/comictalker/comictalker.py index cd62fa0..a23eaaf 100644 --- a/comictalker/comictalker.py +++ b/comictalker/comictalker.py @@ -107,6 +107,7 @@ class ComicTalker: name: str = "Example" id: str = "example" + ct_req_spec: str = ">=1.6.0a7" # The ComicTagger version required by the talker using PyPA version specifiers website: str = "https://example.com" logo_url: str = f"{website}/logo.png" attribution: str = f"Metadata provided by {name}"