Skip to content

Commit

Permalink
🏗️ proper 3.9 implementation of entrypoitns
Browse files Browse the repository at this point in the history
  • Loading branch information
vokimon committed Dec 4, 2024
1 parent 88b2ea3 commit 865466a
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions customblocks/entrypoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ def iter_entry_points_group__pkg_resources(group):
for entry in entry_points(group=group):
yield entry

def iter_entry_points_group__importlib_dict(group):
""" This was the first version in importlib.metadata.
A short lived api (3.8, 3.9) that returned a dictionary
where the key was the group."""

from importlib.metadata import entry_points
for entry in entry_points()[group]:
yield entry

def iter_entry_points_group__importlib_selectable(group):
""" This is the brand new api that does not
work in all still supported Py3 versions."""
Expand All @@ -21,15 +30,17 @@ def iter_entry_points_group__importlib_selectable(group):
for entry in entry_points(group=group):
yield entry

def iter_entry_points(group):
if sys.version_info < (3,0):
def entry_points_group(group):
if sys.version_info < (3,8):
return iter_entry_points_group__pkg_resources(group)
if sys.version_info < (3,10):
return iter_entry_points_group__importlib_dict(group)
return iter_entry_points_group__importlib_selectable(group)

def load_entry_points(group):
return dict(
(entry.name, entry.load())
for entry in iter_entry_points(group)
for entry in entry_points_group(group)
)


0 comments on commit 865466a

Please sign in to comment.