Skip to content

Commit 5d89971

Browse files
committed
Deal with pre-3.3.0 importlib.metadata
Signed-off-by: Michel Hidalgo <[email protected]>
1 parent 8445319 commit 5d89971

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

rosidl_cli/rosidl_cli/entry_points.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -84,28 +84,32 @@ def get_entry_points(group_name, *, specs=None, strict=False):
8484
specs = normalize_entry_point_specs(specs)
8585

8686
entry_points = {}
87-
entry_points_per_group = importlib_metadata.entry_points()
88-
for entry_point in entry_points_per_group.get(group_name, []):
89-
name = entry_point.name
90-
if name in entry_points:
91-
msg = (f"Found duplicate entry point '{name}': "
92-
'got {entry_point} and {entry_points[name]}')
93-
if strict:
94-
raise RuntimeError(msg)
95-
logger.warning(msg)
96-
continue
97-
if specs:
98-
if name not in specs:
87+
# NOTE(hidmic): importlib.metadata.EntryPoint instances
88+
# only expose their Distribution in version 3.3.0 onwards
89+
for dist in importlib_metadata.distributions():
90+
for entry_point in dist.entry_points:
91+
if entry_point.group != group_name:
9992
continue
100-
version = Version(entry_point.distro.version)
101-
if version not in specs[name]:
102-
msg = (f"Spec '{name}{specs[name]}'"
103-
f' cannot be met: found {version}')
93+
name = entry_point.name
94+
if name in entry_points:
95+
msg = (f"Found duplicate entry point '{name}': "
96+
'got {entry_point} and {entry_points[name]}')
10497
if strict:
10598
raise RuntimeError(msg)
10699
logger.warning(msg)
107100
continue
108-
entry_points[name] = entry_point
101+
if specs:
102+
if name not in specs:
103+
continue
104+
version = Version(dist.version)
105+
if version not in specs[name]:
106+
msg = (f"Spec '{name}{specs[name]}'"
107+
f' cannot be met: found {version}')
108+
if strict:
109+
raise RuntimeError(msg)
110+
logger.warning(msg)
111+
continue
112+
entry_points[name] = entry_point
109113
if specs:
110114
pending = set(specs) - set(entry_points)
111115
if pending:

0 commit comments

Comments
 (0)