From de2bbc53c67a7714f8c5602473ab3671156c70be Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sun, 26 May 2024 11:02:19 +0200 Subject: [PATCH] Support both `@procedure` and `@procedure(name)` notations. --- platypush/config/__init__.py | 2 +- platypush/procedure/__init__.py | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/platypush/config/__init__.py b/platypush/config/__init__.py index 7f69159314..c6859e02bb 100644 --- a/platypush/config/__init__.py +++ b/platypush/config/__init__.py @@ -355,7 +355,7 @@ class Config: prefix = modname + '.' if prefix is None else prefix self.procedures.update( **{ - getattr(obj, 'procedure_name', f'{prefix}.{name}'): obj + (getattr(obj, 'procedure_name', None) or f'{prefix}{name}'): obj for name, obj in inspect.getmembers(module) if is_functional_procedure(obj) } diff --git a/platypush/procedure/__init__.py b/platypush/procedure/__init__.py index 7ef0cadd32..478b3a64b6 100644 --- a/platypush/procedure/__init__.py +++ b/platypush/procedure/__init__.py @@ -558,7 +558,9 @@ class IfProcedure(Procedure): return response -def procedure(name: Optional[str] = None): +def procedure(name_or_func: Optional[str] = None, *upper_args, **upper_kwargs): + name = name_or_func if isinstance(name_or_func, str) else None + def func_wrapper(f): """ Public decorator to mark a function as a procedure. @@ -569,10 +571,15 @@ def procedure(name: Optional[str] = None): @wraps(f) def _execute_procedure(*args, **kwargs): + args = [*upper_args, *args] + kwargs = {**upper_kwargs, **kwargs} return exec_wrapper(f, *args, **kwargs) return _execute_procedure + if callable(name_or_func): + return func_wrapper(name_or_func) + return func_wrapper