From ad336e7e150e109557eae2873816646cc623d8c6 Mon Sep 17 00:00:00 2001 From: Chris Ghyzel Date: Sat, 18 May 2024 21:35:47 -0700 Subject: [PATCH 1/5] fix init_parser_plugins for python 3.12 --- lute/parse/registry.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lute/parse/registry.py b/lute/parse/registry.py index 731343ea..2958d267 100644 --- a/lute/parse/registry.py +++ b/lute/parse/registry.py @@ -5,6 +5,7 @@ """ from importlib.metadata import entry_points +from sys import version_info from lute.parse.base import AbstractParser from lute.parse.space_delimited_parser import SpaceDelimitedParser, TurkishParser @@ -24,14 +25,20 @@ def init_parser_plugins(): """ Initialize parsers from plugins """ - custom_parser_eps = entry_points().get("lute.plugin.parse", []) + + if version_info.major == 3 and version_info.minor in (8, 9, 10, 11): + custom_parser_eps = entry_points().get('lute.plugin.parse') + elif version_info.major == 3 and version_info.minor == 12: + custom_parser_eps = entry_points().select(group='lute.plugin.parse') + else: + custom_parser_eps = None + if custom_parser_eps is None: + return for custom_parser_ep in custom_parser_eps: if _is_valid(custom_parser_ep.load()): __LUTE_PARSERS__[custom_parser_ep.name] = custom_parser_ep.load() else: - raise ValueError( - f"{custom_parser_ep.name} is not a subclass of AbstractParser" - ) + raise ValueError(f"{custom_parser_ep.name} is not a a subclass of AbstractParser") def _is_valid(custom_parser): From 97bebe761cbcba3bebfd6ae30067c776753a9486 Mon Sep 17 00:00:00 2001 From: Chris Ghyzel Date: Sat, 18 May 2024 22:16:22 -0700 Subject: [PATCH 2/5] fix init_parser_plugins for python 3.12 reformatted the ValueError in init_parser_plugins to conform with black's formatting standard --- lute/parse/registry.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lute/parse/registry.py b/lute/parse/registry.py index 2958d267..510a7838 100644 --- a/lute/parse/registry.py +++ b/lute/parse/registry.py @@ -38,7 +38,9 @@ def init_parser_plugins(): if _is_valid(custom_parser_ep.load()): __LUTE_PARSERS__[custom_parser_ep.name] = custom_parser_ep.load() else: - raise ValueError(f"{custom_parser_ep.name} is not a a subclass of AbstractParser") + raise ValueError( + f"{custom_parser_ep.name} is not a a subclass of AbstractParser" + ) def _is_valid(custom_parser): From b2166b88ae90eefc94b6e00cf531a147543afa70 Mon Sep 17 00:00:00 2001 From: Jeff Zohrab Date: Sun, 19 May 2024 10:04:37 -0700 Subject: [PATCH 3/5] Assume entry_points().select() will work going forward. --- lute/parse/registry.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/lute/parse/registry.py b/lute/parse/registry.py index 510a7838..08e8d83a 100644 --- a/lute/parse/registry.py +++ b/lute/parse/registry.py @@ -26,20 +26,27 @@ def init_parser_plugins(): Initialize parsers from plugins """ - if version_info.major == 3 and version_info.minor in (8, 9, 10, 11): - custom_parser_eps = entry_points().get('lute.plugin.parse') - elif version_info.major == 3 and version_info.minor == 12: - custom_parser_eps = entry_points().select(group='lute.plugin.parse') + vmaj = version_info.major + vmin = version_info.minor + if vmaj == 3 and vmin in (8, 9, 10, 11): + custom_parser_eps = entry_points().get("lute.plugin.parse") + elif (vmaj == 3 and vmin >= 12) or (vmaj >= 4): + # Can't be sure this will always work, API may change again, + # but can't plan for the unforseeable everywhere. + custom_parser_eps = entry_points().select(group="lute.plugin.parse") else: - custom_parser_eps = None - if custom_parser_eps is None: + # earlier version of python than 3.8? What madness is this? + # Not going to throw, just print and hope the user sees it. + msg = f"Unable to load plugins for python {vmaj}.{vmin}, please upgrade to 3.8+" + print(msg, flush=True) return + for custom_parser_ep in custom_parser_eps: if _is_valid(custom_parser_ep.load()): __LUTE_PARSERS__[custom_parser_ep.name] = custom_parser_ep.load() else: raise ValueError( - f"{custom_parser_ep.name} is not a a subclass of AbstractParser" + f"{custom_parser_ep.name} is not a subclass of AbstractParser" ) From 52f6c51f6037a13d838721808606632203c6c776 Mon Sep 17 00:00:00 2001 From: Jeff Zohrab Date: Sun, 19 May 2024 10:16:39 -0700 Subject: [PATCH 4/5] Add python 3.12 to ci. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 299bf5c9..b5706b80 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,7 @@ jobs: strategy: matrix: - python_version: [ '3.8', '3.9', '3.10', '3.11' ] + python_version: [ '3.8', '3.9', '3.10', '3.11', '3.12' ] steps: From 5dbfd28e2d5857373246b027f41b5e5053279695 Mon Sep 17 00:00:00 2001 From: Jeff Zohrab Date: Sun, 19 May 2024 10:43:17 -0700 Subject: [PATCH 5/5] Exit if no plugins. --- lute/parse/registry.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lute/parse/registry.py b/lute/parse/registry.py index 08e8d83a..81e5c08a 100644 --- a/lute/parse/registry.py +++ b/lute/parse/registry.py @@ -41,6 +41,9 @@ def init_parser_plugins(): print(msg, flush=True) return + if custom_parser_eps is None: + return + for custom_parser_ep in custom_parser_eps: if _is_valid(custom_parser_ep.load()): __LUTE_PARSERS__[custom_parser_ep.name] = custom_parser_ep.load()