|
7 | 7 | from bs4 import BeautifulSoup
|
8 | 8 |
|
9 | 9 | # 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) |
13 | 14 |
|
14 | 15 | build_dir = sys.argv[1]
|
15 | 16 | print(f"Build directory: {build_dir}")
|
|
39 | 40 | "": "", # root dir for index.rst
|
40 | 41 | }
|
41 | 42 |
|
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): |
45 | 44 | try:
|
46 | 45 | result = subprocess.run(
|
47 |
| - ["git", "log", "--diff-filter=A", "--format=%aD", "--", file_path], |
| 46 | + ["git", "log"] + git_log_args + ["--", file_path], |
48 | 47 | capture_output=True,
|
49 | 48 | text=True,
|
50 | 49 | check=True,
|
51 | 50 | )
|
52 | 51 | 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") |
59 | 54 | except subprocess.CalledProcessError:
|
60 |
| - return "Unknown" |
| 55 | + pass |
| 56 | + raise ValueError(f"Could not find date for {file_path}") |
61 | 57 |
|
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") |
64 | 60 | 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") |
84 | 62 |
|
85 | 63 | # Try to find the source file with the given base path and the extensions .rst and .py
|
86 | 64 | def find_source_file(base_path):
|
@@ -178,3 +156,6 @@ def process_json_file(json_file_path):
|
178 | 156 | "or `make html` build. Warnings about these files when you run `make html-noplot` "
|
179 | 157 | "can be ignored."
|
180 | 158 | )
|
| 159 | + |
| 160 | +if __name__ == "__main__": |
| 161 | + main() |
0 commit comments