Coverage for tsfpga/examples/build_module_documentation.py: 0%

26 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-03-11 20:51 +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# -------------------------------------------------------------------------------------------------- 

8 

9import shutil 

10import sys 

11from pathlib import Path 

12 

13# Do PYTHONPATH insert() instead of append() to prefer any local repo checkout over any pip install. 

14THIS_DIR = Path(__file__).parent 

15REPO_ROOT = THIS_DIR.parent.parent.resolve() 

16sys.path.insert(0, str(REPO_ROOT)) 

17 

18from tsfpga.about import REPOSITORY_URL 

19from tsfpga.examples.example_env import TSFPGA_EXAMPLES_TEMP_DIR, get_tsfpga_example_modules 

20from tsfpga.module_documentation import ModuleDocumentation 

21from tsfpga.system_utils import create_file 

22from tsfpga.tools.sphinx_doc import build_sphinx 

23 

24GENERATED_SPHINX_RST = TSFPGA_EXAMPLES_TEMP_DIR / "example_sphinx_rst" 

25GENERATED_SPHINX_HTML = TSFPGA_EXAMPLES_TEMP_DIR / "example_sphinx_html" 

26 

27 

28def main() -> None: 

29 generate_documentation() 

30 

31 shutil.copyfile(THIS_DIR / "conf.py", GENERATED_SPHINX_RST / "conf.py") 

32 build_sphinx(build_path=GENERATED_SPHINX_RST, output_path=GENERATED_SPHINX_HTML) 

33 

34 

35def generate_documentation() -> None: 

36 index_rst = """ 

37Documentation of example modules 

38================================ 

39 

40.. toctree:: 

41 :caption: Modules 

42 :hidden: 

43 

44""" 

45 

46 for module in get_tsfpga_example_modules(): 

47 output_path = GENERATED_SPHINX_RST / "modules" / module.name 

48 

49 index_rst += f" modules/{module.name}/{module.name}\n" 

50 

51 ModuleDocumentation( 

52 module=module, 

53 repository_url=f"{REPOSITORY_URL}/tree/main/{module.path.relative_to(REPO_ROOT)}", 

54 repository_name="GitHub", 

55 ).create_rst_document(output_path=output_path) 

56 

57 create_file(GENERATED_SPHINX_RST / "index.rst", contents=index_rst) 

58 

59 

60if __name__ == "__main__": 

61 main()