Skip to content

Commit

Permalink
Add legacy tool API docs
Browse files Browse the repository at this point in the history
  • Loading branch information
olofk committed Nov 17, 2023
1 parent 2860547 commit 76a3ee6
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
6 changes: 6 additions & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,9 @@

# Take class documentation from both __init__(), and the class docstring.
autoclass_content = "both"

from edalize.edatool import gen_tool_docs

s = gen_tool_docs()
with open(os.path.join(os.path.abspath("."), "edam/tools.rst"), "w") as f:
f.write(s)
1 change: 1 addition & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ The :ref:`Edalize Developer Guide <dg>` describes how to work with Edalize to fi
:hidden:

edam/api
edam/tools
Modules <edalize>
genindex
Module Index <py-modindex>
43 changes: 43 additions & 0 deletions edalize/edatool.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,3 +524,46 @@ def _write_fileset_to_f_file(
unused_files.append(src_file)

return unused_files


def _class_doc(items):
s = items["description"] + "\n\n"
lines = []
name_len = 10
type_len = 4
for item in items.get("members", []):
name_len = max(name_len, len(item["name"]))
type_len = max(type_len, len(item["type"]))
lines.append((item["name"], item["type"], item["desc"]))
for item in items.get("dicts", []):
name_len = max(name_len, len(item["name"]))
type_len = max(type_len, len(item["type"]) + 8)
lines.append((item["name"], "Dict of {}".format(item["type"]), item["desc"]))
for item in items.get("lists", {}):
name_len = max(name_len, len(item["name"]))
type_len = max(type_len, len(item["type"]) + 8)
lines.append((item["name"], "List of {}".format(item["type"]), item["desc"]))

s += "=" * name_len + " " + "=" * type_len + " " + "=" * 11 + "\n"
s += "Field Name".ljust(name_len + 1) + "Type".ljust(type_len + 1) + "Description\n"
s += "=" * name_len + " " + "=" * type_len + " " + "=" * 11 + "\n"
for line in lines:
s += line[0].ljust(name_len + 1)
s += line[1].ljust(type_len + 1)
s += line[2]
s += "\n"
s += "=" * name_len + " " + "=" * type_len + " " + "=" * 11 + "\n"
return s


def gen_tool_docs():
s = ""
for backend in get_edatools():
name = backend.__name__

if name == "Edatool":
continue

s += "\n{}\n{}\n\n".format(name, "~" * len(name))
s += _class_doc(backend.get_doc(0))
return s

0 comments on commit 76a3ee6

Please sign in to comment.