Skip to content

Commit 71fc84a

Browse files
committed
you can not have nice things with unstable APIs
1 parent 77d91fd commit 71fc84a

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

src/mxmake/topics.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@
1010
import typing
1111

1212

13+
try:
14+
# do we have Python 3.12+
15+
from importlib.metadata import EntryPoints # type: ignore # noqa: F401
16+
17+
HAS_IMPORTLIB_ENTRYPOINTS = True
18+
except ImportError:
19+
HAS_IMPORTLIB_ENTRYPOINTS = False
20+
21+
1322
@dataclass
1423
class Setting:
1524
name: str
@@ -165,9 +174,14 @@ def domain(self, name: str) -> typing.Optional[Domain]:
165174

166175
@functools.lru_cache(maxsize=4096)
167176
def load_topics() -> typing.List[Topic]:
168-
eps = entry_points()
169-
ep_topics = [ep for ep in eps if ep.group == "mxmake.topics"]
170-
return [ep.load() for ep in ep_topics]
177+
if HAS_IMPORTLIB_ENTRYPOINTS:
178+
topics_eps = entry_points(group="mxmake.topics") # type: ignore
179+
else:
180+
eps = entry_points()
181+
if "mxmake.topics" not in eps:
182+
return []
183+
topics_eps = eps["mxmake.topics"]
184+
return [ep.load() for ep in topics_eps] # type: ignore
171185

172186

173187
def get_topic(name: str) -> Topic:

0 commit comments

Comments
 (0)