Coverage for tsfpga/examples/build_module_documentation.py: 0%
26 statements
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-20 20:52 +0000
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-20 20:52 +0000
1# --------------------------------------------------------------------------------------------------
2# Copyright (c) Lukas Vik. All rights reserved.
3#
4# This file is part of the tsfpga project, a project platform for modern FPGA development.
5# https://tsfpga.com
6# https://github.com/tsfpga/tsfpga
7# --------------------------------------------------------------------------------------------------
9# Standard libraries
10import shutil
11import sys
12from pathlib import Path
14# Do PYTHONPATH insert() instead of append() to prefer any local repo checkout over any pip install.
15THIS_DIR = Path(__file__).parent
16REPO_ROOT = THIS_DIR.parent.parent.resolve()
17sys.path.insert(0, str(REPO_ROOT))
19# First party libraries
20from tsfpga.about import REPOSITORY_URL
21from tsfpga.examples.example_env import TSFPGA_EXAMPLES_TEMP_DIR, get_tsfpga_example_modules
22from tsfpga.module_documentation import ModuleDocumentation
23from tsfpga.system_utils import create_file
24from tsfpga.tools.sphinx_doc import build_sphinx
26GENERATED_SPHINX_RST = TSFPGA_EXAMPLES_TEMP_DIR / "example_sphinx_rst"
27GENERATED_SPHINX_HTML = TSFPGA_EXAMPLES_TEMP_DIR / "example_sphinx_html"
30def main() -> None:
31 generate_documentation()
33 shutil.copyfile(THIS_DIR / "conf.py", GENERATED_SPHINX_RST / "conf.py")
34 build_sphinx(build_path=GENERATED_SPHINX_RST, output_path=GENERATED_SPHINX_HTML)
37def generate_documentation() -> None:
38 index_rst = """
39Documentation of example modules
40================================
42.. toctree::
43 :caption: Modules
44 :hidden:
46"""
48 for module in get_tsfpga_example_modules():
49 output_path = GENERATED_SPHINX_RST / "modules" / module.name
51 index_rst += f" modules/{module.name}/{module.name}\n"
53 ModuleDocumentation(
54 module=module,
55 repository_url=f"{REPOSITORY_URL}/tree/main/{module.path.relative_to(REPO_ROOT)}",
56 repository_name="GitHub",
57 ).create_rst_document(output_path=output_path)
59 create_file(GENERATED_SPHINX_RST / "index.rst", contents=index_rst)
62if __name__ == "__main__":
63 main()