Skip to content

Commit

Permalink
feat(py v12): use new standard for importlib
Browse files Browse the repository at this point in the history
  • Loading branch information
ModernMAK committed Jul 7, 2024
1 parent d5a063e commit d951b5a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ classifiers = [
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)"
]
dependencies = ["typing-extensions; python_version < '3.12'"]
description = "The core library used by other Relic-Tool packages."
dynamic = ["version"]
name = "relic-tool-core"
requires-python = ">=3.9"
dependencies = [
"importlib_metadata >= 3.6"
]

[project.readme]
content-type = "text/markdown"
Expand Down
4 changes: 2 additions & 2 deletions src/relic/core/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ def load_plugins(self) -> None:
Load all entrypoints using the group specified by the class-variable GROUP
"""

all_entry_points: Dict[str, List[EntryPoint]] = entry_points() # type: ignore[assignment, unused-ignore]
for ep in all_entry_points.get(self.GROUP, []):
all_entry_points: EntryPoints = entry_points() # type: ignore[assignment, unused-ignore]
for ep in all_entry_points.select(group = self.GROUP):
ep_func: CliEntrypoint = ep.load()
ep_func(parent=self.subparsers)

Expand Down
8 changes: 5 additions & 3 deletions src/relic/core/entrytools.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from __future__ import annotations

from importlib.metadata import entry_points, EntryPoint
from importlib.metadata import entry_points, EntryPoint, EntryPoints
from typing import (
TypeVar,
Protocol,
Expand All @@ -30,6 +30,8 @@
_TValue_co = TypeVar("_TValue_co", covariant=True) # pylint: disable=invalid-name




class KeyFunc(Protocol[_TKey_contra]): # pylint: disable=too-few-public-methods
"""
A function which converts an object to a string representation for an entrypoint
Expand Down Expand Up @@ -144,8 +146,8 @@ def load_entrypoints(self) -> None:
"""
Load all entrypoints from the group specified in __init__
"""
all_entrypoints: Dict[str, List[EntryPoint]] = entry_points() # type: ignore[assignment, unused-ignore]
group_entrypoints: List[EntryPoint] = all_entrypoints.get(self._ep_group, [])
all_entrypoints: EntryPoints = entry_points()
group_entrypoints: List[EntryPoint] = all_entrypoints.select(group=self._ep_group)
for ep in group_entrypoints:
ep_name: str = ep.name
ep_func: _TValue = ep.load()
Expand Down

0 comments on commit d951b5a

Please sign in to comment.