Skip to content

Commit

Permalink
fix: make plugin data accept extra params (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronabebe committed Mar 5, 2024
1 parent 3b09e25 commit 017ee09
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/nendo/schema/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ def plugin_type(self) -> str:
@staticmethod
def plugin_data(
*args, **kwargs
) -> Callable[[NendoPlugin, NendoTrack], Dict[str, Any]]:
) -> Union[
Callable[[NendoPlugin, NendoTrack], Dict[str, Any]],
Callable
]:
"""Decorator to enrich a NendoTrack with data from a plugin.
Args:
Expand All @@ -95,9 +98,9 @@ def plugin_data(
"""
if len(args) == 1 and callable(args[0]) and not kwargs:
func = args[0]
def wrapper(self, track: NendoTrack):
def wrapper(self, track: NendoTrack, *params: Any) -> Dict[str, Any]:
try:
f_result = func(self, track)
f_result = func(self, track, *params)
except NendoError as e:
raise NendoPluginRuntimeError(
f"Error running plugin function: {e}",
Expand All @@ -111,8 +114,8 @@ def wrapper(self, track: NendoTrack):
)
return f_result
return wrapper
def plugin_func(func: Callable[[NendoPlugin, NendoTrack], Dict[str, Any]]):
def wrapper(self, track: NendoTrack):
def plugin_func(func: Callable[[NendoPlugin, NendoTrack, Any], Dict[str, Any]]):
def wrapper(self, track: NendoTrack, *params: Any) -> Dict[str, Any]:
# check if return values are declared and already exist
if self.config.replace_plugin_data is False:
all_values_present = True
Expand All @@ -127,7 +130,7 @@ def wrapper(self, track: NendoTrack):
if all_values_present:
return all_values
try:
f_result = func(self, track)
f_result = func(self, track, *params)
except NendoError as e:
raise NendoPluginRuntimeError(
f"Error running plugin function: {e}",
Expand Down
Binary file added tests/assets/silence.mp3
Binary file not shown.

0 comments on commit 017ee09

Please sign in to comment.