Skip to content

Commit f21b5c0

Browse files
committed
Address feedback
1 parent 137f995 commit f21b5c0

File tree

2 files changed

+18
-37
lines changed

2 files changed

+18
-37
lines changed

insert_last_verified.py renamed to .jenkins/insert_last_verified.py

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
from bs4 import BeautifulSoup
88

99
# Check if the build directory is provided as an argument in the Makefile
10-
if len(sys.argv) < 2:
11-
print("Error: Build directory not provided. Exiting.")
12-
exit(1)
10+
def main():
11+
if len(sys.argv) < 2:
12+
print("Error: Build directory not provided. Exiting.")
13+
exit(1)
1314

1415
build_dir = sys.argv[1]
1516
print(f"Build directory: {build_dir}")
@@ -39,48 +40,25 @@
3940
"": "", # root dir for index.rst
4041
}
4142

42-
43-
# Use git log to get the creation date of the file
44-
def get_creation_date(file_path):
43+
def get_git_log_date(file_path, git_log_args):
4544
try:
4645
result = subprocess.run(
47-
["git", "log", "--diff-filter=A", "--format=%aD", "--", file_path],
46+
["git", "log"] + git_log_args + ["--", file_path],
4847
capture_output=True,
4948
text=True,
5049
check=True,
5150
)
5251
if result.stdout:
53-
creation_date = result.stdout.splitlines()[0]
54-
creation_date = datetime.strptime(creation_date, "%a, %d %b %Y %H:%M:%S %z")
55-
formatted_date = creation_date.strftime("%b %d, %Y")
56-
else:
57-
formatted_date = "Unknown"
58-
return formatted_date
52+
date_str = result.stdout.splitlines()[0]
53+
return datetime.strptime(date_str, "%a, %d %b %Y %H:%M:%S %z")
5954
except subprocess.CalledProcessError:
60-
return "Unknown"
55+
pass
56+
raise ValueError(f"Could not find date for {file_path}")
6157

62-
63-
# Use git log to get the last updated date of the file
58+
def get_creation_date(file_path):
59+
return get_git_log_date(file_path, ["--diff-filter=A", "--format=%aD"]).strftime("%b %d, %Y")
6460
def get_last_updated_date(file_path):
65-
try:
66-
result = subprocess.run(
67-
["git", "log", "-1", "--format=%aD", "--", file_path],
68-
capture_output=True,
69-
text=True,
70-
check=True,
71-
)
72-
if result.stdout:
73-
last_updated_date = result.stdout.strip()
74-
last_updated_date = datetime.strptime(
75-
last_updated_date, "%a, %d %b %Y %H:%M:%S %z"
76-
)
77-
formatted_date = last_updated_date.strftime("%b %d, %Y")
78-
else:
79-
formatted_date = "Unknown"
80-
return formatted_date
81-
except subprocess.CalledProcessError:
82-
return "Unknown"
83-
61+
return get_git_log_date(file_path, ["-1", "--format=%aD"]).strftime("%b %d, %Y")
8462

8563
# Try to find the source file with the given base path and the extensions .rst and .py
8664
def find_source_file(base_path):
@@ -178,3 +156,6 @@ def process_json_file(json_file_path):
178156
"or `make html` build. Warnings about these files when you run `make html-noplot` "
179157
"can be ignored."
180158
)
159+
160+
if __name__ == "__main__":
161+
main()

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ docs:
9494
make download
9595
make download-last-reviewed-json
9696
make html
97-
@python insert_last_verified.py $(BUILDDIR)/html
97+
@python .jenkins/insert_last_verified.py $(BUILDDIR)/html
9898
rm -rf docs
9999
cp -r $(BUILDDIR)/html docs
100100
touch docs/.nojekyll
@@ -107,7 +107,7 @@ html-noplot:
107107
make download-last-reviewed-json
108108
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
109109
@echo "Running post-processing script to insert 'Last Verified' dates..."
110-
@python insert_last_verified.py $(BUILDDIR)/html
110+
@python .jenkins/insert_last_verified.py $(BUILDDIR)/html
111111
rm -rf tutorials-review-data.json
112112

113113
clean-cache:

0 commit comments

Comments
 (0)