From 12dd06c55824cc2201cd11b83255b4e389e74468 Mon Sep 17 00:00:00 2001 From: Mizaki Date: Thu, 30 Nov 2023 01:50:28 +0000 Subject: [PATCH 1/4] 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}" From f977e7056222815c0c3264aabf4dec6334c550c9 Mon Sep 17 00:00:00 2001 From: Mizaki Date: Fri, 1 Dec 2023 01:23:46 +0000 Subject: [PATCH 2/4] Rename min ct required var. Use a minimum version only check instead of full spec --- comictalker/__init__.py | 10 +++++----- comictalker/comictalker.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/comictalker/__init__.py b/comictalker/__init__.py index 08a7fd1..11eff4b 100644 --- a/comictalker/__init__.py +++ b/comictalker/__init__.py @@ -4,7 +4,7 @@ import logging import pathlib import sys -from packaging.specifiers import InvalidSpecifier, SpecifierSet +from packaging.version import InvalidVersion, parse if sys.version_info < (3, 10): from importlib_metadata import entry_points @@ -33,14 +33,14 @@ def get_talkers(version: str, cache: pathlib.Path) -> dict[str, ComicTalker]: logger.error("Talker ID must be the same as the entry point name") continue try: - if version in SpecifierSet(obj.ct_req_spec, prereleases=True): + if parse(version) >= parse(obj.comictagger_min_ver): talkers[talker.name] = obj else: logger.error( - f"CT required version not met for talker: {talker.name} with specifier: {obj.ct_req_spec}" + f"CT minimum required version not met for talker: {talker.name} with version: {obj.comictagger_min_ver}" ) - except InvalidSpecifier: - logger.error(f"Invalid specifier for talker: {talker.name} - specifier: {obj.ct_req_spec}") + except InvalidVersion: + logger.error(f"Invalid version number for talker: {talker.name} - version: {obj.comictagger_min_ver}") except Exception: logger.exception("Failed to load talker: %s", talker.name) diff --git a/comictalker/comictalker.py b/comictalker/comictalker.py index a23eaaf..6024e1b 100644 --- a/comictalker/comictalker.py +++ b/comictalker/comictalker.py @@ -107,7 +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 + 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 {name}" From 4d2b9e1157db520d49a81d81562d7b4c55120cb4 Mon Sep 17 00:00:00 2001 From: Mizaki Date: Fri, 1 Dec 2023 14:09:17 +0000 Subject: [PATCH 3/4] Warn on bad min ct required verion and use anyway. Use clearer log messages --- comictalker/__init__.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/comictalker/__init__.py b/comictalker/__init__.py index 11eff4b..c2f92f8 100644 --- a/comictalker/__init__.py +++ b/comictalker/__init__.py @@ -37,10 +37,15 @@ def get_talkers(version: str, cache: pathlib.Path) -> dict[str, ComicTalker]: talkers[talker.name] = obj else: logger.error( - f"CT minimum required version not met for talker: {talker.name} with version: {obj.comictagger_min_ver}" + f"Minimum ComicTagger version required of {obj.comictagger_min_ver} for talker {talker.name} is not met, will NOT load talker" ) except InvalidVersion: - logger.error(f"Invalid version number for talker: {talker.name} - version: {obj.comictagger_min_ver}") + 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) From fc6e0c3db39469639cbf439b5960db63a5fe5ada Mon Sep 17 00:00:00 2001 From: Mizaki Date: Tue, 12 Dec 2023 23:47:47 +0000 Subject: [PATCH 4/4] Parse ct version only once --- comictalker/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/comictalker/__init__.py b/comictalker/__init__.py index c2f92f8..540d023 100644 --- a/comictalker/__init__.py +++ b/comictalker/__init__.py @@ -24,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: @@ -33,7 +34,7 @@ def get_talkers(version: str, cache: pathlib.Path) -> dict[str, ComicTalker]: logger.error("Talker ID must be the same as the entry point name") continue try: - if parse(version) >= parse(obj.comictagger_min_ver): + if ct_version >= parse(obj.comictagger_min_ver): talkers[talker.name] = obj else: logger.error(