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
|
prefix = modname + '.' if prefix is None else prefix
|
||||||
self.procedures.update(
|
self.procedures.update(
|
||||||
**{
|
**{
|
||||||
prefix + name: obj
|
getattr(obj, 'procedure_name', f'{prefix}.{name}'): obj
|
||||||
for name, obj in inspect.getmembers(module)
|
for name, obj in inspect.getmembers(module)
|
||||||
if is_functional_procedure(obj)
|
if is_functional_procedure(obj)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import re
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
from queue import LifoQueue
|
from queue import LifoQueue
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from ..common import exec_wrapper
|
from ..common import exec_wrapper
|
||||||
from ..config import Config
|
from ..config import Config
|
||||||
|
@ -557,18 +558,22 @@ class IfProcedure(Procedure):
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
def procedure(f):
|
def procedure(name: Optional[str] = None):
|
||||||
"""
|
def func_wrapper(f):
|
||||||
Public decorator to mark a function as a procedure.
|
"""
|
||||||
"""
|
Public decorator to mark a function as a procedure.
|
||||||
|
"""
|
||||||
|
|
||||||
f.procedure = True
|
f.procedure = True
|
||||||
|
f.procedure_name = name
|
||||||
|
|
||||||
@wraps(f)
|
@wraps(f)
|
||||||
def _execute_procedure(*args, **kwargs):
|
def _execute_procedure(*args, **kwargs):
|
||||||
return exec_wrapper(f, *args, **kwargs)
|
return exec_wrapper(f, *args, **kwargs)
|
||||||
|
|
||||||
return _execute_procedure
|
return _execute_procedure
|
||||||
|
|
||||||
|
return func_wrapper
|
||||||
|
|
||||||
|
|
||||||
# vim:sw=4:ts=4:et:
|
# vim:sw=4:ts=4:et:
|
||||||
|
|
Loading…
Reference in a new issue