From 450f6478f870135ea79abd1b4a77085b70ed9fe1 Mon Sep 17 00:00:00 2001 From: tengxianglin Date: Tue, 2 Jul 2024 10:44:41 +0800 Subject: [PATCH] Update update_quairkit_rst.py --- docs/update_quairkit_rst.py | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/docs/update_quairkit_rst.py b/docs/update_quairkit_rst.py index 9789860..d5f14a0 100644 --- a/docs/update_quairkit_rst.py +++ b/docs/update_quairkit_rst.py @@ -47,15 +47,14 @@ def _list_quairkit_files( relative_path = os.path.join(base_path, child).replace(os.path.sep, ".") if os.path.isdir(child_path): - sub_list = _list_quairkit_files(child_path, relative_path, []) - if sub_list: # 仅当子目录非空时才添加 + if sub_list := _list_quairkit_files(child_path, relative_path, []): file_name_attr_list.append((f"quairkit.{relative_path}", "folder")) file_name_attr_list.extend(sub_list) elif child.endswith(".py"): file_name_attr_list.append( (f"quairkit.{relative_path.replace('.py', '')}", "python") ) - + file_name_attr_list = [ sub_array for sub_array in file_name_attr_list @@ -126,7 +125,7 @@ def _update_index_rst( Welcome to {_platform_name}'s documentation! ==================================== -|quairkit| `Go to {_platform_name} Home `_ +|quairkit| `Go to QuAIR-Platform Home `_ """ @@ -145,11 +144,11 @@ def _get_modules_rst( file_list: List[Tuple[str, str]], source_directory: str = _sphinx_source_dir ): file_list_copy = file_list.copy() - rst_content = "" - for item in file_list_copy: - if item[0].count(".") == 1: - rst_content += f"\n {item[0]}" - return rst_content + return "".join( + f"\n {item[0]}" + for item in file_list_copy + if item[0].count(".") == 1 + ) def _update_conf_py(source_directory: str = _sphinx_source_dir): @@ -274,11 +273,10 @@ def _update_conf_py(source_directory: str = _sphinx_source_dir): _platform_dir_path = os.path.dirname(os.path.dirname(_current_script_path)) _current_working_dir = os.getcwd() - if _current_working_dir == _platform_dir_path: - result = _list_quairkit_files() - os.makedirs(_sphinx_source_dir, exist_ok=True) - _update_index_rst(result) - _update_function_rst(result) - _update_conf_py() - else: + if _current_working_dir != _platform_dir_path: raise SystemExit(f"The current working directory is not {_platform_dir_path}.") + result = _list_quairkit_files() + os.makedirs(_sphinx_source_dir, exist_ok=True) + _update_index_rst(result) + _update_function_rst(result) + _update_conf_py()