Expose the wrapped function in @action.

Added a `wrapped` "hidden" parameter to the function returned by the
`@action` decorator.

We need this to access the underlying decorated function when e.g. we
need to access its specs or decorators.
This commit is contained in:
Fabio Manganiello 2023-10-09 22:35:08 +02:00
parent 1e93af86f4
commit 52e353dc14
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774
2 changed files with 5 additions and 1 deletions

View file

@ -56,6 +56,8 @@ def action(f: Callable[..., Any]) -> Callable[..., Response]:
# Propagate the docstring # Propagate the docstring
_execute_action.__doc__ = f.__doc__ _execute_action.__doc__ = f.__doc__
# Expose the wrapped function
_execute_action.wrapped = f # type: ignore
return _execute_action return _execute_action
@ -64,6 +66,7 @@ class Plugin(EventGenerator, ExtensionWithManifest): # lgtm [py/missing-call-to
def __init__(self, **kwargs): def __init__(self, **kwargs):
super().__init__() super().__init__()
self.logger = logging.getLogger( self.logger = logging.getLogger(
'platypush:plugin:' + get_plugin_name_by_class(self.__class__) 'platypush:plugin:' + get_plugin_name_by_class(self.__class__)
) )
@ -264,6 +267,7 @@ class AsyncRunnablePlugin(RunnablePlugin, ABC):
""" """
Initialize an event loop and run the listener as a task. Initialize an event loop and run the listener as a task.
""" """
assert self._loop, 'The loop is not initialized'
asyncio.set_event_loop(self._loop) asyncio.set_event_loop(self._loop)
self._task = self._loop.create_task(self._listen()) self._task = self._loop.create_task(self._listen())

View file

@ -107,7 +107,7 @@ def get_plugin_class_by_name(plugin_name) -> Optional[type]:
return None return None
def get_plugin_name_by_class(plugin) -> Optional[str]: def get_plugin_name_by_class(plugin) -> str:
"""Gets the common name of a plugin (e.g. "music.mpd" or "media.vlc") given its class.""" """Gets the common name of a plugin (e.g. "music.mpd" or "media.vlc") given its class."""
from platypush.plugins import Plugin from platypush.plugins import Plugin