Skip to content

Commit

Permalink
refactor: better handling of plugin types for ModelHook manager
Browse files Browse the repository at this point in the history
  • Loading branch information
hellkite500 committed Jul 25, 2024
1 parent 059000e commit a4710a9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 2 additions & 3 deletions python/ngen_cal/src/ngen/cal/_plugin_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ def setup_plugin_manager(plugins: list[Callable | ModuleType]) -> PluginManager:
pm.add_hookspecs(_hookspec)

for plugin in plugins:
assert not isinstance(plugin, ModuleType), "function plugins"
if isinstance(plugin, Callable):
pm.register(plugin())
elif isinstance(plugin, ModuleType):
pm.register(plugin)
else:
assert_never(plugin)
assert_never()

return pm

Expand Down
5 changes: 4 additions & 1 deletion python/ngen_cal/src/ngen/cal/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,10 @@ class Config(BaseModel.Config):
def __init__(self, *args, **kwargs):
super().__init__(**kwargs)
model_plugins = cast(List[Union[Callable, ModuleType]], self.plugins)
self._plugin_manager = setup_scoped_plugin_manager(ModelHooks, model_plugins)
try:
self._plugin_manager = setup_scoped_plugin_manager(ModelHooks, model_plugins)
except AssertionError as e:
raise RuntimeError("At this time, model plugins do not support function based plugins.")

#FIXME formalize type: str = "ModelName"
def get_binary(self)->str:
Expand Down

0 comments on commit a4710a9

Please sign in to comment.