Skip to content

Commit

Permalink
you can not have nice things with unstable APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
jensens committed Feb 27, 2024
1 parent 77d91fd commit 2672e85
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/mxmake/topics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"]
return [ep.load() for ep in topics_eps]


def get_topic(name: str) -> Topic:
Expand Down

0 comments on commit 2672e85

Please sign in to comment.