Exemple #1
0
def print_signature(function):
    sig = inspect.signature(function)
    header = function.__name__
    color_header = t.bold(header)

    return wrap_lines_with_color_header(color_header, header, str(sig),
                                        initial_indent='')
Exemple #2
0
    def walk(it, provider=''):
        for spec in it:
            tp, name, value = spec
            #If we require it for the current provider '' drop the past one.
            if name not in res_providers or res_providers[name] != '':
                res_providers[name] = provider

            if name in seen:
                continue
            seen.add(name)
            if tp == 'config':
                config_lines[name] = format_config_line(name, value[0], sig_index=0)
                walk(value[1:], name)


            elif tp == 'provider':
                #We only care about the first level of nested providers.
                if provider=='':
                    walk(value[1:], name)
                else:
                    walk(value[1:], provider)

            elif tp == 'unknown':
                val_tp = get_annotation_string(value.annotation)
                default = ' = {}'.format(value.default
                                   if value.default is not value.empty else '')
                line = "  {}{}{}".format(t.bold(name), val_tp, default)
                unknown_lines[name] = line
            else:
                raise ValueError("Unknown walk spec")
Exemple #3
0
def format_config_line(val, function, sig_index=1):
    #Get the docs
    doc = function.__doc__
    if doc is None:
        doc = ''

    #Get the recognized type
    tp = get_parser_type(function, sig_index=sig_index)



    color_header = "%s%s: " %(t.bold(val), tp)
    white_header = "%s%s: " %(val, tp)
    return wrap_lines_with_color_header(color_header, white_header, doc)
Exemple #4
0
def format_providermodule(module):
    moddoc = sane_fill(module.__doc__, initial_indent='', subsequent_indent='')
    if moddoc is None:
        moddoc = ''

    functions = get_providers(module)
    lines = []

    name = t.bold_underline(module.__name__)

    for val, function in functions.items():

        #Get the docs
        doc = function.__doc__
        if doc is None:
            doc = ''

        if hasattr(function, 'highlight'):
            highlight = '(%s)' % function.highlight
            color_highlight = get_highlight_color(function.highlight)(highlight)
        else:
            color_highlight = highlight = ''


        color_header = "%s%s: "%(t.bold(val), color_highlight)
        white_header = "%s%s:"%(val, highlight)
        lines.append(wrap_lines_with_color_header(color_header, white_header, doc))



    lines = '\n\n'.join(lines)



    s = ("{name}\n{moddoc}\n"
        "The following providers are defined in this module:\n\n"
        "{lines}".format(name=name, moddoc = moddoc, lines=lines))
    return s