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

use importlib.metadata to load entrypoints #28

Merged
merged 6 commits into from
Feb 27, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
you can not have nice things with unstable APIs
jensens committed Feb 27, 2024
commit 2a37c30446a94d5e299d91f8922f13d3182ec5cc
20 changes: 17 additions & 3 deletions src/mxmake/topics.py
Original file line number Diff line number Diff line change
@@ -10,6 +10,15 @@
import typing


try:
# do we have Python 3.12+
from importlib.metadata import EntryPoints # type: ignore # noqa: F401

HAS_IMPORTLIB_ENTRYPOINTS = True
except ImportError:
HAS_IMPORTLIB_ENTRYPOINTS = False


@dataclass
class Setting:
name: str
@@ -165,9 +174,14 @@ def domain(self, name: str) -> typing.Optional[Domain]:

@functools.lru_cache(maxsize=4096)
def load_topics() -> typing.List[Topic]:
eps = entry_points()
ep_topics = [ep for ep in eps if ep.group == "mxmake.topics"]
return [ep.load() for ep in ep_topics]
if HAS_IMPORTLIB_ENTRYPOINTS:
topics_eps = entry_points(group="mxmake.topics") # type: ignore
else:
eps = entry_points()
if "mxmake.topics" not in eps:
return []
topics_eps = eps["mxmake.topics"] # type: ignore
return [ep.load() for ep in topics_eps] # type: ignore


def get_topic(name: str) -> Topic: