Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 424 fix init parser plugins #426

Merged
merged 5 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading