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

adapt to new import.metadata.entry_points API #53

Merged
merged 1 commit into from
Oct 22, 2022
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
7 changes: 2 additions & 5 deletions ocrd_browser/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
from ocrd_browser.ui import MainWindow, AboutDialog, OpenDialog
from ocrd_browser.view import ViewRegistry

try:
from importlib.metadata import entry_points
except ModuleNotFoundError:
from importlib_metadata import entry_points # type: ignore
from importlib_metadata import entry_points # type: ignore


class OcrdBrowserApplication(Gtk.Application):
Expand Down Expand Up @@ -40,7 +37,7 @@ def do_startup(self) -> None:
self.set_accels_for_action('view.zoom_to::width', ['<Ctrl>numbersign'])
self.set_accels_for_action('view.zoom_to::page', ['<Ctrl><Alt>numbersign'])

for entry_point in entry_points().get('ocrd_browser_ext', []):
for entry_point in entry_points(group='ocrd_browser_ext'):
(entry_point.load())(self)

self.load_css()
Expand Down
8 changes: 3 additions & 5 deletions ocrd_browser/view/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
from typing import Dict, Tuple, Optional, Type
from .base import View

try:
from importlib.metadata import entry_points
except ModuleNotFoundError:
from importlib_metadata import entry_points # type: ignore
from importlib_metadata import entry_points # type: ignore


ViewInfo = Tuple[type, str, str]
Expand All @@ -18,7 +15,8 @@ def __init__(self, views: Dict[str, ViewInfo]):
@classmethod
def create_from_entry_points(cls) -> ViewRegistry:
views = {}
for entry_point in entry_points().get('ocrd_browser_view', []):
# also loads view plugins, e.g. from browse-ocrd-physical-import
for entry_point in entry_points(group='ocrd_browser_view'):
view_class = entry_point.load()
assert issubclass(view_class, View)
label = view_class.label if hasattr(view_class, 'label') else view_class.__name__
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ setuptools
lxml
Shapely
Deprecated
importlib_metadata;python_version<'3.8'
importlib_resources;python_version<'3.8'
importlib_metadata>=3.6
importlib_resources;python_version<'3.8'