From 52e353dc14dec025a315e080575f9a0c99e8f2a9 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Mon, 9 Oct 2023 22:35:08 +0200 Subject: [PATCH] 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. --- platypush/plugins/__init__.py | 4 ++++ platypush/utils/__init__.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/platypush/plugins/__init__.py b/platypush/plugins/__init__.py index 39cb9f32b..e3db3c777 100644 --- a/platypush/plugins/__init__.py +++ b/platypush/plugins/__init__.py @@ -56,6 +56,8 @@ def action(f: Callable[..., Any]) -> Callable[..., Response]: # Propagate the docstring _execute_action.__doc__ = f.__doc__ + # Expose the wrapped function + _execute_action.wrapped = f # type: ignore return _execute_action @@ -64,6 +66,7 @@ class Plugin(EventGenerator, ExtensionWithManifest): # lgtm [py/missing-call-to def __init__(self, **kwargs): super().__init__() + self.logger = logging.getLogger( '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. """ + assert self._loop, 'The loop is not initialized' asyncio.set_event_loop(self._loop) self._task = self._loop.create_task(self._listen()) diff --git a/platypush/utils/__init__.py b/platypush/utils/__init__.py index 29905c0b2..2bcd6ff87 100644 --- a/platypush/utils/__init__.py +++ b/platypush/utils/__init__.py @@ -107,7 +107,7 @@ def get_plugin_class_by_name(plugin_name) -> Optional[type]: 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.""" from platypush.plugins import Plugin