From 529a603128d5e9dc4701322f44961f165e2183e1 Mon Sep 17 00:00:00 2001 From: omnisci3nce Date: Sun, 14 Jul 2024 21:47:25 +1000 Subject: generate api docs python --- scripts/apidocs/gen_apidocs.py | 109 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 scripts/apidocs/gen_apidocs.py (limited to 'scripts/apidocs/gen_apidocs.py') diff --git a/scripts/apidocs/gen_apidocs.py b/scripts/apidocs/gen_apidocs.py new file mode 100644 index 0000000..390a081 --- /dev/null +++ b/scripts/apidocs/gen_apidocs.py @@ -0,0 +1,109 @@ +# Generates a static webpage for the public C-API of `celeritas-core` +import re +import os +from pathlib import Path + +# --- HTML Fragments +page_start = """ + + + + + + + + + + + + + + + + Celeritas core API + + +
+""" + +page_header = """ +
+

CELERITAS CORE DOCS

+
+""" + +page_footer = """ +
+
+""" + +page_end = """ +
+ + +""" + +def emit_function_sig(signature: str) -> str: + return f""" +
  • +
    {signature}
    +
  • + """ + +categories = { + "RAL": "src/ral", + "Render": "src/new_render" +} + +def find_pub_functions_in_folder(folder_path): + functions = [] + for filename in os.listdir(folder_path): + filepath = os.path.join(folder_path, filename) + if os.path.isfile(filepath): + file_funcs = find_pub_functions_in_file(filepath) + functions.extend(file_funcs) + + return functions + +def find_pub_functions_in_file(file_path): + pattern = r'PUB\s+(\w+\s+)*(\w+)\s+(\w+)\s*\((.*?)\)' + + with open(file_path, 'r') as file: + content = file.read() + + matches = re.finditer(pattern, content, re.MULTILINE) + + # Collect all the functions into an array + functions = [] + for match in matches: + signature = match.group(0) + if signature.startswith("PUB "): + signature = signature[4:] + + print(signature) + functions.append(signature) + + return functions + +def generate_html(): + html_filepath = "index.html" + + script_dir = Path(__file__).resolve().parent + grandparent_dir = script_dir.parents[1] + + with open(html_filepath, 'w') as export_file: + export_file.write(page_start) + export_file.write(page_header) + # TODO: make the actual content + for category in categories.keys(): + folder = os.path.join(grandparent_dir, categories[category]) + category_funcs = find_pub_functions_in_folder(folder) + export_file.write(f"

    {category}

    ") + export_file.write("") + export_file.write(page_end) + +if __name__ == "__main__": + generate_html() -- cgit v1.2.3-70-g09d2