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
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
10 changes: 6 additions & 4 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
node-version: 16
python-version: 3.12
- uses: actions/setup-node@v4
with:
node-version: 18

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

Expand Down
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

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

- Use importlib.metadata to load entrypoints.

## 1.0a3 (2024-02-06)

- Add `typecheck` target and use it for mypy instead of `check` target.
Expand Down
4 changes: 0 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ dependencies = [
dynamic = ["readme"]

[project.optional-dependencies]
mypy = [
"types-setuptools",
"types-pkg-resources",
]
docs = ["Sphinx", "sphinxcontrib-mermaid"]
test = ["zope.testrunner"]

Expand Down
20 changes: 18 additions & 2 deletions src/mxmake/topics.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from collections import Counter
from dataclasses import dataclass
from importlib.metadata import entry_points
from pathlib import Path
from pkg_resources import iter_entry_points

import configparser
import functools
Expand All @@ -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,7 +174,14 @@ def domain(self, name: str) -> typing.Optional[Domain]:

@functools.lru_cache(maxsize=4096)
def load_topics() -> typing.List[Topic]:
return [ep.load() for ep in iter_entry_points("mxmake.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:
Expand Down
Loading