Skip to content

Commit

Permalink
update the api reference names
Browse files Browse the repository at this point in the history
  • Loading branch information
Alleria1809 committed Jul 2, 2024
1 parent 2a545c9 commit 2b61b10
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
5 changes: 3 additions & 2 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
23 changes: 9 additions & 14 deletions docs/source/change_api_file_name.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
update_file_content(diretory)

0 comments on commit 2b61b10

Please sign in to comment.