Skip to content

Commit

Permalink
improve dual compatibility for importlib entry_points
Browse files Browse the repository at this point in the history
  • Loading branch information
tfoote committed Jan 26, 2024
1 parent 1fe5ede commit 9266e57
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/rocker/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,11 +461,26 @@ def generate_dockerfile(extensions, args_dict, base_image):
return dockerfile_str


def list_entry_points():
entry_points = importlib_metadata.entry_points()
if hasattr(entry_points, 'select'):
styles_groups = entry_points.select(group='flake8_import_order.styles')
else:
styles_groups = entry_points.get('flake8_import_order.styles', [])

return styles_groups

def list_plugins(extension_point='rocker.extensions'):

all_entry_points = importlib_metadata.entry_points()
if hasattr(all_entry_points, 'select'):
rocker_extensions = all_entry_points.select(group=extension_point)
else:
rocker_extensions = all_entry_points.get(extension_point, [])

unordered_plugins = {
entry_point.name: entry_point.load()
for entry_point
in importlib_metadata.entry_points().select(group=extension_point)
for entry_point in rocker_extensions
}
# Order plugins by extension point name for consistent ordering below
plugin_names = list(unordered_plugins.keys())
Expand Down

0 comments on commit 9266e57

Please sign in to comment.