Skip to content

Commit 6ec8bbf

Browse files
authored
Merge pull request #28 from mxstack/no-pkg_resources
use importlib.metadata to load entrypoints
2 parents b59e34d + e5bb2d3 commit 6ec8bbf

File tree

4 files changed

+26
-10
lines changed

4 files changed

+26
-10
lines changed

.github/workflows/docs.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ jobs:
77
runs-on: ubuntu-latest
88

99
steps:
10-
- uses: actions/checkout@v3
11-
- uses: actions/setup-python@v4
12-
- uses: actions/setup-node@v3
10+
- uses: actions/checkout@v4
11+
- uses: actions/setup-python@v5
1312
with:
14-
node-version: 16
13+
python-version: 3.12
14+
- uses: actions/setup-node@v4
15+
with:
16+
node-version: 18
1517

1618
- run: npm install -g @mermaid-js/mermaid-cli
1719

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
- Use `pathlib.Path` instead of `os.path`.
3838

39+
- Use importlib.metadata to load entrypoints.
40+
3941
## 1.0a3 (2024-02-06)
4042

4143
- Add `typecheck` target and use it for mypy instead of `check` target.

pyproject.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ dependencies = [
2929
dynamic = ["readme"]
3030

3131
[project.optional-dependencies]
32-
mypy = [
33-
"types-setuptools",
34-
"types-pkg-resources",
35-
]
3632
docs = ["Sphinx", "sphinxcontrib-mermaid"]
3733
test = ["zope.testrunner"]
3834

src/mxmake/topics.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from collections import Counter
22
from dataclasses import dataclass
3+
from importlib.metadata import entry_points
34
from pathlib import Path
4-
from pkg_resources import iter_entry_points
55

66
import configparser
77
import functools
@@ -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,7 +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-
return [ep.load() for ep in iter_entry_points("mxmake.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"] # type: ignore
184+
return [ep.load() for ep in topics_eps] # type: ignore
169185

170186

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

0 commit comments

Comments
 (0)