From 4fef19e3480e91edf24592a095aed8b679b6ec63 Mon Sep 17 00:00:00 2001 From: Michael Carlstrom Date: Sat, 28 Sep 2024 14:54:40 -0400 Subject: [PATCH] fix entry_points Signed-off-by: Michael Carlstrom --- rosidl_cli/rosidl_cli/entry_points.py | 23 ++++++++++++++--------- rosidl_cli/rosidl_cli/extensions.py | 9 ++++----- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/rosidl_cli/rosidl_cli/entry_points.py b/rosidl_cli/rosidl_cli/entry_points.py index 5bdb754b3..c4900a890 100644 --- a/rosidl_cli/rosidl_cli/entry_points.py +++ b/rosidl_cli/rosidl_cli/entry_points.py @@ -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 @@ -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 @@ -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( diff --git a/rosidl_cli/rosidl_cli/extensions.py b/rosidl_cli/rosidl_cli/extensions.py index 9aa2334a4..bbc28c9e7 100644 --- a/rosidl_cli/rosidl_cli/extensions.py +++ b/rosidl_cli/rosidl_cli/extensions.py @@ -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 @@ -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] = []