forked from platypush/platypush
Allow for custom procedure names on the @procedure
decorator.
``` @procedure("foo") def bar(): ... ``` Will now be published as `procedure.foo` instead of `procedure.<module>.bar`.
This commit is contained in:
parent
cbc58c7330
commit
5c2204f99d
2 changed files with 15 additions and 10 deletions
|
@ -355,7 +355,7 @@ class Config:
|
|||
prefix = modname + '.' if prefix is None else prefix
|
||||
self.procedures.update(
|
||||
**{
|
||||
prefix + name: obj
|
||||
getattr(obj, 'procedure_name', f'{prefix}.{name}'): obj
|
||||
for name, obj in inspect.getmembers(module)
|
||||
if is_functional_procedure(obj)
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import re
|
|||
from functools import wraps
|
||||
|
||||
from queue import LifoQueue
|
||||
from typing import Optional
|
||||
|
||||
from ..common import exec_wrapper
|
||||
from ..config import Config
|
||||
|
@ -557,18 +558,22 @@ class IfProcedure(Procedure):
|
|||
return response
|
||||
|
||||
|
||||
def procedure(f):
|
||||
"""
|
||||
Public decorator to mark a function as a procedure.
|
||||
"""
|
||||
def procedure(name: Optional[str] = None):
|
||||
def func_wrapper(f):
|
||||
"""
|
||||
Public decorator to mark a function as a procedure.
|
||||
"""
|
||||
|
||||
f.procedure = True
|
||||
f.procedure = True
|
||||
f.procedure_name = name
|
||||
|
||||
@wraps(f)
|
||||
def _execute_procedure(*args, **kwargs):
|
||||
return exec_wrapper(f, *args, **kwargs)
|
||||
@wraps(f)
|
||||
def _execute_procedure(*args, **kwargs):
|
||||
return exec_wrapper(f, *args, **kwargs)
|
||||
|
||||
return _execute_procedure
|
||||
return _execute_procedure
|
||||
|
||||
return func_wrapper
|
||||
|
||||
|
||||
# vim:sw=4:ts=4:et:
|
||||
|
|
Loading…
Reference in a new issue