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:
Fabio Manganiello 2024-05-24 20:07:24 +02:00
parent cbc58c7330
commit 5c2204f99d
Signed by: blacklight
GPG key ID: D90FBA7F76362774
2 changed files with 15 additions and 10 deletions

View file

@ -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)
}

View file

@ -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,12 +558,14 @@ class IfProcedure(Procedure):
return response
def procedure(f):
def procedure(name: Optional[str] = None):
def func_wrapper(f):
"""
Public decorator to mark a function as a procedure.
"""
f.procedure = True
f.procedure_name = name
@wraps(f)
def _execute_procedure(*args, **kwargs):
@ -570,5 +573,7 @@ def procedure(f):
return _execute_procedure
return func_wrapper
# vim:sw=4:ts=4:et: