Esempio n. 1
0
def generate_md_toc(entries, url, depth=2):
    assert url.endswith("/")
    entries = [e for e in entries if not e.get("skip_from_toc")]
    generated = ""
    if set(len(x.get("generate", [])) for x in entries) == {1}:
        print_generate = False
    else:
        print_generate = True
    for entry in entries:
        title = entry["title"]
        path = entry["path"]
        full_url = url + path
        children = entry.get("children")
        generate = entry.get("generate")
        if children or (print_generate and generate):
            title_prefix = "### "
        else:
            title_prefix = "- "
        generated += title_prefix + "[{title}]({full_url})\n".format(
            title=title, full_url=full_url
        )
        if children:
            assert path.endswith("/")
            for child in children:
                if child.get("skip_from_toc", False):
                    continue
                child_title = child["title"]
                child_path = child["path"]
                child_url = full_url + child_path
                generated += "- [{child_title}]({child_url})\n".format(
                    child_title=child_title, child_url=child_url
                )
            generated += "\n"
        elif generate and print_generate:
            for gen in generate:
                obj = docstrings.import_object(gen)
                obj_name = docstrings.get_name(obj)
                obj_type = docstrings.get_type(obj)
                link = "{full_url}/#{obj_name}-{obj_type}".format(
                    full_url=full_url, obj_name=obj_name, obj_type=obj_type
                ).lower()
                name = gen.split(".")[-1]
                generated += "- [{name} {obj_type}]({link})\n".format(
                    name=name, obj_type=obj_type, link=link
                )
            generated += "\n"
    return generated
Esempio n. 2
0
        def recursive_make_map(entry, current_url):
            current_url /= entry["path"]
            entry_map = {}
            if "generate" in entry:
                for symbol in entry["generate"]:
                    object_ = docstrings.import_object(symbol)
                    object_type = docstrings.get_type(object_)
                    object_name = symbol.split(".")[-1]

                    if symbol.startswith("tensorflow.keras."):
                        symbol = symbol.replace("tensorflow.keras.", "keras.")
                    object_name = object_name.lower().replace("_", "")
                    entry_map[symbol] = (str(current_url) + "#" + object_name +
                                         "-" + object_type)

            if "children" in entry:
                for child in entry["children"]:
                    entry_map.update(recursive_make_map(child, current_url))
            return entry_map