2020
2121def rename_subpackage_toc (subpackage : str , toc : Dict ):
2222 """
23- Extend table of contents sections with subpackage name prefix .
23+ Extend table of contents sections with the subpackage name as the parent folder .
2424
2525 Args:
2626 subpackage (str): subpackage name.
@@ -29,21 +29,73 @@ def rename_subpackage_toc(subpackage: str, toc: Dict):
2929 for item in toc :
3030 for file in item ["sections" ]:
3131 if "local" in file :
32- file ["local" ] = f"{ subpackage } _ " + file ["local" ]
32+ file ["local" ] = f"{ subpackage } / " + file ["local" ]
3333 else :
3434 # if "local" is not in file, it means we have a subsection, hence the recursive call
3535 rename_subpackage_toc (subpackage , [file ])
3636
3737
38+ def rename_copy_subpackage_html_paths (subpackage : str , subpackage_path : Path , optimum_path : Path , version : str ):
39+ """
40+ Copy and rename the files from the given subpackage's documentation to Optimum's documentation.
41+ In Optimum's documentation, the subpackage files are organized as follows:
42+
43+ optimum_doc
44+ ├──────── subpackage_1
45+ │ ├────── folder_1
46+ │ │ └───── ...
47+ │ ├────── ...
48+ │ └────── folder_x
49+ │ └───── ...
50+ ├──────── ...
51+ ├──────── subpackage_n
52+ │ ├────── folder_1
53+ │ │ └───── ...
54+ │ ├────── ...
55+ │ └────── folder_y
56+ │ └───── ...
57+ └──────── usual_optimum_doc
58+
59+ Args:
60+ subpackage (str): subpackage name
61+ subpackage_path (Path): path to the subpackage's documentation
62+ optimum_path (Path): path to Optimum's documentation
63+ version (str): Optimum's version
64+ """
65+ subpackage_html_paths = list (subpackage_path .rglob ("*.html" ))
66+ # The language folder is the 4th folder in the subpackage HTML paths
67+ language_folder_level = 3
68+
69+ for html_path in subpackage_html_paths :
70+ language_folder = html_path .parts [language_folder_level ]
71+ # Build the relative path from the language folder
72+ relative_path_from_language_folder = Path (* html_path .parts [language_folder_level + 1 :])
73+ # New path in Optimum's doc
74+ new_path_in_optimum = Path (
75+ f"{ optimum_path } /optimum/{ version } /{ language_folder } /{ subpackage } /{ relative_path_from_language_folder } "
76+ )
77+ # Build the parent folders if necessary
78+ new_path_in_optimum .parent .mkdir (parents = True , exist_ok = True )
79+
80+ shutil .copyfile (html_path , new_path_in_optimum )
81+
82+
3883def main ():
3984 args = parser .parse_args ()
4085 optimum_path = Path ("optimum-doc-build" )
86+
87+ # Copy and rename all files from subpackages' docs to Optimum doc
4188 for subpackage in args .subpackages :
4289 subpackage_path = Path (f"{ subpackage } -doc-build" )
90+
4391 # Copy all HTML files from subpackage into optimum
44- subpackage_html_paths = list (subpackage_path .rglob ("*.html" ))
45- for html_path in subpackage_html_paths :
46- shutil .copyfile (html_path , f"{ optimum_path } /optimum/{ args .version } /en/{ subpackage } _{ html_path .name } " )
92+ rename_copy_subpackage_html_paths (
93+ subpackage ,
94+ subpackage_path ,
95+ optimum_path ,
96+ args .version ,
97+ )
98+
4799 # Load optimum table of contents
48100 base_toc_path = next (optimum_path .rglob ("_toctree.yml" ))
49101 with open (base_toc_path , "r" ) as f :
@@ -52,7 +104,7 @@ def main():
52104 subpackage_toc_path = next (subpackage_path .rglob ("_toctree.yml" ))
53105 with open (subpackage_toc_path , "r" ) as f :
54106 subpackage_toc = yaml .safe_load (f )
55- # Extend table of contents sections with subpackage name prefix
107+ # Extend table of contents sections with the subpackage name as the parent folder
56108 rename_subpackage_toc (subpackage , subpackage_toc )
57109 # Update optimum table of contents
58110 base_toc .extend (subpackage_toc )
0 commit comments