-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_build_timestamp.py
More file actions
38 lines (29 loc) · 1.2 KB
/
update_build_timestamp.py
File metadata and controls
38 lines (29 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""Update build timestamp in _version.py before building."""
from datetime import datetime
from pathlib import Path
VERSION_FILE = Path(__file__).parent / "cognite" / "databricks" / "_version.py"
def update_build_timestamp() -> None:
"""Update __build_timestamp__ in _version.py with current datetime."""
content = VERSION_FILE.read_text()
timestamp = datetime.now().isoformat()
# Simple replacement: find the line and replace it
lines = content.splitlines()
new_lines = []
found = False
for line in lines:
if line.strip().startswith("__build_timestamp__"):
new_lines.append(f'__build_timestamp__ = "{timestamp}" # Set during build')
found = True
else:
new_lines.append(line)
# If not found, add it after __version__
if not found:
new_lines = []
for line in lines:
new_lines.append(line)
if line.strip().startswith("__version__"):
new_lines.append(f'__build_timestamp__ = "{timestamp}" # Set during build')
VERSION_FILE.write_text("\n".join(new_lines) + "\n")
print(f"Updated build timestamp to: {timestamp}")
if __name__ == "__main__":
update_build_timestamp()