From 16d0933323fef4151ef4f8f2f5bcb8779426d5de Mon Sep 17 00:00:00 2001 From: xuzhenyoumi Date: Sat, 20 Sep 2025 01:10:16 +0800 Subject: [PATCH] modify make_index_rst function --- .../generate_pr_html.py | 42 +++++++------------ 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/tools/ci_pipeline_gate_APIView/generate_pr_html.py b/tools/ci_pipeline_gate_APIView/generate_pr_html.py index d8efb8f22d..4a16f364c4 100644 --- a/tools/ci_pipeline_gate_APIView/generate_pr_html.py +++ b/tools/ci_pipeline_gate_APIView/generate_pr_html.py @@ -588,35 +588,23 @@ def make_index_rst(target_path, language_f): len(title_content) + '\n\n' + \ '.. toctree::\n :glob:\n :maxdepth: 1\n\n' dir_set = set() - added_entries = set() # 用于存储已经添加的条目 # pylint: disable=W0612 for rt, dirs, files in os.walk(os.path.join(target_path, 'api_python')): - for file in files: - if file.endswith('.rst') and rt.split('api_python')[-1] not in dir_set: - if not rt.split('api_python')[-1]: - entry = f" api_python/{file}\n" - content += entry - added_entries.add(entry) - elif not os.path.basename(rt).startswith('_'): - entry = f" api_python{rt.split('api_python')[-1]}/*\n" - content += entry - added_entries.add(entry) - else: - continue - dir_set.add(rt.split('api_python')[-1]) - - mint_entry = " api_python/mint/*\n" - tools_entry = " api_python/mindspore.tools.rst\n" - utils_entry = " api_python/mindspore.utils.rst\n" - if mint_entry not in added_entries: - content += mint_entry - added_entries.add(mint_entry) - if tools_entry not in added_entries: - content += tools_entry - added_entries.add(tools_entry) - if utils_entry not in added_entries: - content += utils_entry - added_entries.add(utils_entry) + # ------------- 根目录 ------------- + if rt.split('api_python')[-1] == '': + for file in files: + if file.endswith('.rst'): + content += f" api_python/{file}\n" + # ------- 目录下有.rst文件且非_开头的子目录 ------- + elif (rt.split('api_python')[-1] not in dir_set and + not os.path.basename(rt).startswith('_') and + any(file.endswith('.rst') for file in files)): + content += f" api_python{rt.split('api_python')[-1]}/*\n" + dir_set.add(rt.split('api_python')[-1]) + else: + continue + + content += " api_python/mint/*\n" with open(os.path.join(target_path, 'index.rst'), 'w+', encoding='utf-8') as f: f.write(content) -- Gitee