Skip to content

Allow the service description to be passed as argument #886

Open

Description

@schauveau

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:

def generate_color_service(color):

    @service(f'test.color_{color}')
    def color_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"

    return color_service

test_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:

def gen_action_selector(argname, color): 
     """ Helper to generate the selector for the color service arguments"""
     ... 

def generate_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)
    def color_service(action=None):
        """ This is not used when a description is provided as argument """
	log.info(f"The color is {name}")

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions