From 8334a0f502c6aa072d35bf7ba144aff0de8bb97d Mon Sep 17 00:00:00 2001 From: nsprenkle Date: Thu, 8 Aug 2024 11:13:23 -0400 Subject: [PATCH] refactor: move override behavior into default select --- xblock/plugin.py | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/xblock/plugin.py b/xblock/plugin.py index fb0888e08..17c324223 100644 --- a/xblock/plugin.py +++ b/xblock/plugin.py @@ -30,20 +30,9 @@ def __init__(self, all_entry_points): def default_select(identifier, all_entry_points): # pylint: disable=inconsistent-return-statements """ - Raise an exception when we have ambiguous entry points. - """ - - if len(all_entry_points) == 0: - raise PluginMissingError(identifier) - if len(all_entry_points) == 1: - return all_entry_points[0] - elif len(all_entry_points) > 1: - raise AmbiguousPluginError(all_entry_points) + Select the appropriate entry point for a given block. + Honors the ability to override and take preference over the default entry point. - -def select_with_overrides(identifier, all_entry_points): # pylint: disable=inconsistent-return-statements - """ - Return overridden entry point, if present. Otherwise returns entry point. Raise an exception when we have ambiguous entry points. """ @@ -60,13 +49,13 @@ def select_with_overrides(identifier, all_entry_points): # pylint: disable=inco # Overrides get priority if len(overrides) == 1: return overrides[0] - if len(overrides) > 1: + elif len(overrides) > 1: raise AmbiguousPluginError(all_entry_points) # ... then default behavior - if len(block_entry_points) == 0: + elif len(block_entry_points) == 0: raise PluginMissingError(identifier) - if len(block_entry_points) == 1: + elif len(block_entry_points) == 1: return all_entry_points[0] elif len(block_entry_points) > 1: raise AmbiguousPluginError(all_entry_points) @@ -129,7 +118,7 @@ def select(identifier, all_entry_points): if key not in PLUGIN_CACHE: if select is None: - select = select_with_overrides + select = default_select all_entry_points = [ *importlib.metadata.entry_points(group=f'{cls.entry_point}.overrides', name=identifier),