Skip to content

Commit

Permalink
Merge pull request #426 from LuteOrg/issue_425_fix_init_parser_plugins
Browse files Browse the repository at this point in the history
Issue 424 fix init parser plugins
  • Loading branch information
jzohrab authored May 19, 2024
2 parents 5fe4206 + 5dbfd28 commit 089b2d9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
21 changes: 20 additions & 1 deletion 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,7 +25,25 @@ def init_parser_plugins():
"""
Initialize parsers from plugins
"""
custom_parser_eps = entry_points().get("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:
# 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

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()
Expand Down

0 comments on commit 089b2d9

Please sign in to comment.