Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
svekars committed Dec 2, 2024
1 parent 137f995 commit f21b5c0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 37 deletions.
51 changes: 16 additions & 35 deletions insert_last_verified.py → .jenkins/insert_last_verified.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
from bs4 import BeautifulSoup

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

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


# Use git log to get the creation date of the file
def get_creation_date(file_path):
def get_git_log_date(file_path, git_log_args):
try:
result = subprocess.run(
["git", "log", "--diff-filter=A", "--format=%aD", "--", file_path],
["git", "log"] + git_log_args + ["--", file_path],
capture_output=True,
text=True,
check=True,
)
if result.stdout:
creation_date = result.stdout.splitlines()[0]
creation_date = datetime.strptime(creation_date, "%a, %d %b %Y %H:%M:%S %z")
formatted_date = creation_date.strftime("%b %d, %Y")
else:
formatted_date = "Unknown"
return formatted_date
date_str = result.stdout.splitlines()[0]
return datetime.strptime(date_str, "%a, %d %b %Y %H:%M:%S %z")
except subprocess.CalledProcessError:
return "Unknown"
pass
raise ValueError(f"Could not find date for {file_path}")


# Use git log to get the last updated date of the file
def get_creation_date(file_path):
return get_git_log_date(file_path, ["--diff-filter=A", "--format=%aD"]).strftime("%b %d, %Y")
def get_last_updated_date(file_path):
try:
result = subprocess.run(
["git", "log", "-1", "--format=%aD", "--", file_path],
capture_output=True,
text=True,
check=True,
)
if result.stdout:
last_updated_date = result.stdout.strip()
last_updated_date = datetime.strptime(
last_updated_date, "%a, %d %b %Y %H:%M:%S %z"
)
formatted_date = last_updated_date.strftime("%b %d, %Y")
else:
formatted_date = "Unknown"
return formatted_date
except subprocess.CalledProcessError:
return "Unknown"

return get_git_log_date(file_path, ["-1", "--format=%aD"]).strftime("%b %d, %Y")

# Try to find the source file with the given base path and the extensions .rst and .py
def find_source_file(base_path):
Expand Down Expand Up @@ -178,3 +156,6 @@ def process_json_file(json_file_path):
"or `make html` build. Warnings about these files when you run `make html-noplot` "
"can be ignored."
)

if __name__ == "__main__":
main()
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ docs:
make download
make download-last-reviewed-json
make html
@python insert_last_verified.py $(BUILDDIR)/html
@python .jenkins/insert_last_verified.py $(BUILDDIR)/html
rm -rf docs
cp -r $(BUILDDIR)/html docs
touch docs/.nojekyll
Expand All @@ -107,7 +107,7 @@ html-noplot:
make download-last-reviewed-json
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
@echo "Running post-processing script to insert 'Last Verified' dates..."
@python insert_last_verified.py $(BUILDDIR)/html
@python .jenkins/insert_last_verified.py $(BUILDDIR)/html
rm -rf tutorials-review-data.json

clean-cache:
Expand Down

0 comments on commit f21b5c0

Please sign in to comment.