Skip to content

Commit

Permalink
Fix compatibility with Python < 3.10 importlib.metadata (#585)
Browse files Browse the repository at this point in the history
It appears that the Distribution.name property was introduced in Python
3.10.

Fixes: 5f9f5ff
  • Loading branch information
cottsay committed Sep 25, 2023
1 parent b544529 commit a9de909
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 4 additions & 3 deletions colcon_core/extension_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ def get_all_extension_points():
entry_points = defaultdict(dict)
seen = set()
for dist in distributions():
if dist.name in seen:
dist_name = dist.metadata['Name']
if dist_name in seen:
continue
seen.add(dist.name)
seen.add(dist_name)
for entry_point in dist.entry_points:
# skip groups which are not registered as extension points
if entry_point.group not in colcon_extension_points:
Expand All @@ -69,7 +70,7 @@ def get_all_extension_points():
f"from '{dist._path}' "
f"overwriting '{previous}'")
entry_points[entry_point.group][entry_point.name] = \
(entry_point.value, dist.name, dist.version)
(entry_point.value, dist_name, dist.version)
return entry_points


Expand Down
6 changes: 5 additions & 1 deletion test/test_extension_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@ class Dist():
version = '0.0.0'

def __init__(self, entry_points):
self.name = f'dist-{id(self)}'
self.metadata = {'Name': f'dist-{id(self)}'}
self._entry_points = entry_points

@property
def entry_points(self):
return list(self._entry_points)

@property
def name(self):
return self.metadata['Name']


def iter_entry_points(*, group=None):
if group == EXTENSION_POINT_GROUP_NAME:
Expand Down

0 comments on commit a9de909

Please sign in to comment.