Skip to content

Commit

Permalink
fix entry_points
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
  • Loading branch information
InvincibleRMC committed Sep 28, 2024
1 parent 853e394 commit 4fef19e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
23 changes: 14 additions & 9 deletions rosidl_cli/rosidl_cli/entry_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

import importlib.metadata as importlib_metadata
import logging
from typing import Any, Dict, List, Optional, TYPE_CHECKING
import sys
from typing import Any, Dict, List, Optional, TYPE_CHECKING, Union

if TYPE_CHECKING:
from typing import TypedDict
Expand All @@ -31,16 +32,21 @@ def get_entry_points(group_name: str, *, specs: Optional[List[str]] = None, stri
"""
Get entry points from a specific group.
:param str group_name: the name of the entry point group
:param list specs: an optional collection of entry point names to retrieve
:param bool strict: whether to raise or warn on error
:param group_name: the name of the entry point group
:param specs: an optional collection of entry point names to retrieve
:param strict: whether to raise or warn on error
:returns: mapping from entry point names to ``EntryPoint`` instances
:rtype: dict
"""
if specs is not None:
specs_set = set(specs)
entry_points_impl = importlib_metadata.entry_points()
groups = entry_points_impl.select(group=group_name)
# Select does not exist until python 3.10
if sys.version_info >= (3, 10):
groups: Union[importlib_metadata.EntryPoints, List[importlib_metadata.EntryPoint]] = \
entry_points_impl.select(group=group_name)
else:
groups = entry_points_impl.get(group_name, [])

entry_points: Dict[str, importlib_metadata.EntryPoint] = {}
for entry_point in groups:
name = entry_point.name
Expand Down Expand Up @@ -74,10 +80,9 @@ def load_entry_points(group_name: str, *, strict: bool = False,
See :py:meth:`get_entry_points` for further reference on
additional keyword arguments.
:param str group_name: the name of the entry point group
:param bool strict: whether to raise or warn on error
:param group_name: the name of the entry point group
:param strict: whether to raise or warn on error
:returns: mapping from entry point name to loaded entry point
:rtype: dict
"""
loaded_entry_points: Dict[str, Any] = {}
for name, entry_point in get_entry_points(
Expand Down
9 changes: 4 additions & 5 deletions rosidl_cli/rosidl_cli/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from rosidl_cli.entry_points import load_entry_points

import yaml # type: ignore[import-untyped]
import yaml # type: ignore[import]

if TYPE_CHECKING:
from typing import TypedDict
Expand Down Expand Up @@ -78,12 +78,11 @@ def load_extensions(group_name: str, *, specs: Optional[List[str]] = None,
"""
Load extensions for a specific group.
:param str group_name: the name of the extension group
:param list specs: an optional collection of extension specs
:param group_name: the name of the extension group
:param specs: an optional collection of extension specs
(see :py:meth:`parse_extension_specification` for spec format)
:param bool strict: whether to raise or warn on error
:param strict: whether to raise or warn on error
:returns: a list of :py:class:`Extension` instances
:rtype: list
"""
extensions: List[Extension] = []

Expand Down

0 comments on commit 4fef19e

Please sign in to comment.