Skip to content

Commit

Permalink
Fix entrypoint bug in py3.8/3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
amykyta3 committed Apr 4, 2023
1 parent 03d3729 commit 80f670b
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/peakrdl_regblock/entry_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,21 @@ def _get_entry_points(group_name: str) -> List[Tuple['EntryPoint', 'Distribution
def _get_name_from_dist(dist: 'Distribution') -> str:
return dist.name

elif sys.version_info >= (3,8,0):
elif sys.version_info >= (3,8,0): # pragma: no cover
from importlib import metadata

def _get_entry_points(group_name: str) -> List[Tuple['EntryPoint', 'Distribution']]:
eps = []
dist_names = set()
for dist in metadata.distributions():
# Due to a bug in importlib.metadata's distributions iterator, in
# some cases editable installs will cause duplicate dist entries.
# Filter this out.
dist_name = get_name_from_dist(dist)
if dist_name in dist_names:
continue
dist_names.add(dist_name)

for ep in dist.entry_points:
if ep.group == group_name:
eps.append((ep, dist))
Expand All @@ -30,7 +39,7 @@ def _get_entry_points(group_name: str) -> List[Tuple['EntryPoint', 'Distribution
def _get_name_from_dist(dist: 'Distribution') -> str:
return dist.metadata["Name"]

else:
else: # pragma: no cover
import pkg_resources # type: ignore

def _get_entry_points(group_name: str) -> List[Tuple['EntryPoint', 'Distribution']]:
Expand Down

0 comments on commit 80f670b

Please sign in to comment.