49 lines
1.3 KiB
Python
49 lines
1.3 KiB
Python
import subprocess
|
|
import datetime
|
|
import pathlib
|
|
|
|
root = pathlib.Path(__file__).resolve().parents[1]
|
|
template = root / "sls_build_backend" / "_version.py.in"
|
|
template_dev = root / "sls_build_backend" / "_version_dev.py.in"
|
|
output = root / "sls" / "_version.py"
|
|
|
|
def get_commit():
|
|
try:
|
|
result_hash = subprocess.check_output(
|
|
["git", "describe", "--always", "--dirty", "--abbrev=7"],
|
|
cwd=".",
|
|
stderr=subprocess.DEVNULL,
|
|
text=True
|
|
).strip()
|
|
result_date = subprocess.check_output(
|
|
["git", "show", "-s", "--format=%ci"],
|
|
cwd=".",
|
|
stderr=subprocess.DEVNULL,
|
|
text=True
|
|
).strip()
|
|
return f"{result_hash} {result_date}"
|
|
except Exception:
|
|
return "unknown"
|
|
|
|
def get_timestamp():
|
|
return datetime.datetime.now(datetime.timezone.utc).isoformat() + "Z"
|
|
|
|
def clean_output():
|
|
version = "unknown"
|
|
|
|
text = template_dev.read_text()
|
|
text = text.format(version=version)
|
|
output.write_text(text)
|
|
|
|
def main():
|
|
version = "unknown"
|
|
commit = get_commit()
|
|
timestamp = get_timestamp()
|
|
|
|
text = template.read_text()
|
|
text = text.format(version=version, commit=commit, timestamp=timestamp)
|
|
output.write_text(text)
|
|
|
|
if __name__ == "__main__":
|
|
main()
|