From 2b61b105fd11beea4b3175ea71c863f79b83df4d Mon Sep 17 00:00:00 2001 From: Alleria Date: Tue, 2 Jul 2024 16:02:08 -0700 Subject: [PATCH] update the api reference names --- docs/Makefile | 5 +++-- docs/source/change_api_file_name.py | 23 +++++++++-------------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/docs/Makefile b/docs/Makefile index ad139cf4..b327c069 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -36,8 +36,9 @@ apidoc: @python $(SOURCEDIR)/remove_files.py @echo "Renaming and updating file" @python $(SOURCEDIR)/change_api_file_name.py - - + # @echo "Renaming and updating file" + # @python $(SOURCEDIR)/change_api_file_name_autosummary.py + html: apidoc @$(SPHINXBUILD) -b html "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/docs/source/change_api_file_name.py b/docs/source/change_api_file_name.py index bbf7a00f..a5e8ea4b 100644 --- a/docs/source/change_api_file_name.py +++ b/docs/source/change_api_file_name.py @@ -1,12 +1,14 @@ import os import re -def update_file_content(directory): - module_name = directory.split("/")[-1] - +def update_file_content(directory: str): + module_name = directory.split("/")[-1] if "_autosummary" not in directory else "components" + # print(f"directory: {directory}; module_name {module_name}") for filename in os.listdir(directory): + # print(filename) if filename.endswith(".rst") and "index" not in filename: filepath = os.path.join(directory, filename) + # print(filepath) with open(filepath, "r+", encoding='utf-8') as file: lines = file.readlines() modified = False # To track if modifications have been made @@ -20,6 +22,7 @@ def update_file_content(directory): if line.startswith(module_name): # Replace the full module path with only the last segment new_title = line.split('.')[-1] + # print(f"new_title: {new_title}") lines[i] = new_title + '\n' # Update the title line modified = True # Mark that modification has been made # No need to break since we are preserving the rest of the content @@ -31,14 +34,7 @@ def update_file_content(directory): file.truncate() # Ensure the file is cut off at the new end if it's shorter print(f"Updated {filepath}") -# def rename_files(directory): -# remove_prefix = directory.split("/")[-1] + "." -# for filename in os.listdir(directory): -# if filename.endswith(".rst") and remove_prefix in filename: -# new_filename = filename.replace(remove_prefix, '') -# os.rename(os.path.join(directory, filename), os.path.join(directory, new_filename)) -# print(f"Renamed {filename} to {new_filename}") - + if __name__ == "__main__": # Specify the directory or directories you want to process @@ -49,8 +45,7 @@ def update_file_content(directory): "./source/apis/eval", "./source/apis/tracing", "./source/apis/optim", + # "./source/apis/components/_autosummary", ] for diretory in directories: - update_file_content(diretory) - # rename_files(diretory) - # rename_and_update_files(dir) \ No newline at end of file + update_file_content(diretory) \ No newline at end of file