Skip to content

Commit

Permalink
[doc][build] Update all changed files timestamp to latest (#47115)
Browse files Browse the repository at this point in the history
So these source files serving as dependency for doc files always get
rebuilt correctly.

---------

Signed-off-by: khluu <[email protected]>
  • Loading branch information
khluu authored Aug 13, 2024
1 parent 51963ba commit 4cf30f6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ci/ray_ci/doc/cmd_load_doc_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def list_changed_and_added_files(ray_dir: str, latest_master_commit: str):
)
filenames = []
for file in untracked_files + modified_files + diff_files_with_master:
filename = file.split(".")[0] # Remove extension
filename = file
if filename.startswith("doc/"): # Remove "doc/" prefix
filename = filename.replace("doc/", "")
if filename.startswith("source/"): # Remove "doc/" prefix
Expand Down
20 changes: 17 additions & 3 deletions ci/ray_ci/doc/cmd_update_cache_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ def list_pending_files(ray_dir: str) -> List[str]:
pending_files = f.readlines()
pending_files = [file.strip() for file in pending_files]
os.remove(f"{ray_dir}/{PENDING_FILES_PATH}")
for i in range(len(pending_files)):
if pending_files[i].split(".")[-1] != "py":
pending_files[i] = pending_files[i].split(".")[0]
return pending_files


Expand Down Expand Up @@ -54,7 +57,7 @@ def update_environment_pickle(ray_dir: str, pending_files: List[str]) -> None:


# TODO(@khluu): Check if this is necessary. Only update changed template files.
def update_file_timestamp(ray_dir: str) -> None:
def update_file_timestamp(ray_dir: str, pending_files: List[str]) -> None:
"""
Update files other than source files to
an old timestamp to avoid rebuilding them.
Expand All @@ -71,12 +74,23 @@ def update_file_timestamp(ray_dir: str) -> None:
try:
# Change the access and modification times
os.utime(file_path, (new_timestamp, new_timestamp))
print(f"Changed timestamp for: {file_path}")
except Exception as e:
print(f"Failed to change timestamp for {file_path}: {str(e)}")

# Update Makefile timestamp
os.utime(f"{ray_doc_dir}/Makefile", (new_timestamp, new_timestamp))

new_timestamp = datetime.now().timestamp()
for file in pending_files:
if file.split(".")[-1] != "py":
continue
file_path = os.path.join(ray_dir, file)
try:
# Change the access and modification times
os.utime(file_path, (new_timestamp, new_timestamp))
except Exception as e:
print(f"Failed to change timestamp for {file_path}: {str(e)}")

print("Timestamp change operation completed.")


Expand All @@ -89,7 +103,7 @@ def main(ray_dir: str) -> None:
print("Updating cache environment ...")
pending_files = list_pending_files(ray_dir)
update_environment_pickle(ray_dir, pending_files)
update_file_timestamp(ray_dir)
update_file_timestamp(ray_dir, pending_files)


if __name__ == "__main__":
Expand Down

0 comments on commit 4cf30f6

Please sign in to comment.