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

26 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-04-20 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 

9# Standard libraries 

10import shutil 

11import sys 

12from pathlib import Path 

13 

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)) 

18 

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 

25 

26GENERATED_SPHINX_RST = TSFPGA_EXAMPLES_TEMP_DIR / "example_sphinx_rst" 

27GENERATED_SPHINX_HTML = TSFPGA_EXAMPLES_TEMP_DIR / "example_sphinx_html" 

28 

29 

30def main() -> None: 

31 generate_documentation() 

32 

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) 

35 

36 

37def generate_documentation() -> None: 

38 index_rst = """ 

39Documentation of example modules 

40================================ 

41 

42.. toctree:: 

43 :caption: Modules 

44 :hidden: 

45 

46""" 

47 

48 for module in get_tsfpga_example_modules(): 

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

50 

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

52 

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) 

58 

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

60 

61 

62if __name__ == "__main__": 

63 main()