Skip to content

Commit

Permalink
Update update_quairkit_rst.py
Browse files Browse the repository at this point in the history
  • Loading branch information
tengxianglin committed Jul 2, 2024
1 parent 5d3aace commit 450f647
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions docs/update_quairkit_rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -126,7 +125,7 @@ def _update_index_rst(
Welcome to {_platform_name}'s documentation!
====================================
|quairkit| `Go to {_platform_name} Home <https://quair.github.io/quairkit/>`_
|quairkit| `Go to QuAIR-Platform Home <https://www.quairkit.com/>`_
"""

Expand All @@ -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):
Expand Down Expand Up @@ -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()

0 comments on commit 450f647

Please sign in to comment.