You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow the service description to be passed as argument #886
The service description, text or YAML, is specified with the docstring. Unfortunately, the docstring must be a pure string literal so that means that it has to remain identical when using closures to generate multiple services:
defgenerate_color_service(color):
@service(f'test.color_{color}')defcolor_service(action=None):
"""This is a pure literal. I cannot insert 'color' here """log.info(f"The color is {color}")
color_service.__doc__="changing the __doc__ attribute does not works either"returncolor_servicetest_color_red=generate_color_service('red')
test_color_blue=generate_color_service('blue')
test_color_green=generate_color_service('green')
It would be nice if the description could also be passed as an argument to @service as a string or even better as a python object equivalent to the YAML description. Something like that:
defgen_action_selector(argname, color):
""" Helper to generate the selector for the color service arguments"""
...
defgenerate_color_service(color):
desc= {
'name' : f"test.color_{color}",
'description' : f"This is the {color} service"'fields': {
'action' : gen_action_selector(color)
}
}
@service(description=desc)defcolor_service(action=None):
""" This is not used when a description is provided as argument """log.info(f"The color is {name}")
Activity