forked from platypush/platypush
Support both @procedure
and @procedure(name)
notations.
This commit is contained in:
parent
a4a776986b
commit
de2bbc53c6
2 changed files with 9 additions and 2 deletions
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue