Skip to content

Commit

Permalink
fix init_parser_plugins for python 3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
cghyzel committed May 19, 2024
1 parent 5fe4206 commit ad336e7
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lute/parse/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down

0 comments on commit ad336e7

Please sign in to comment.