Spaces:
Running
Running
File size: 1,451 Bytes
4c19a5a |
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
from functools import lru_cache
import os
import subprocess
from modules.utils import constants
git = os.environ.get("GIT", "git")
@lru_cache()
def commit_hash():
try:
return subprocess.check_output(
[git, "-C", constants.ROOT_DIR, "rev-parse", "HEAD"],
shell=False,
encoding="utf8",
).strip()
except Exception:
return "<none>"
@lru_cache()
def git_tag():
try:
return subprocess.check_output(
[git, "-C", constants.ROOT_DIR, "describe", "--tags"],
shell=False,
encoding="utf8",
).strip()
except Exception:
try:
changelog_md = os.path.join(
os.path.dirname(os.path.dirname(__file__)), "CHANGELOG.md"
)
with open(changelog_md, "r", encoding="utf-8") as file:
line = next((line.strip() for line in file if line.strip()), "<none>")
line = line.replace("## ", "")
return line
except Exception:
return "<none>"
@lru_cache()
def branch_name():
try:
return subprocess.check_output(
[git, "-C", constants.ROOT_DIR, "rev-parse", "--abbrev-ref", "HEAD"],
shell=False,
encoding="utf8",
).strip()
except Exception:
return "<none>"
if __name__ == "__main__":
print(commit_hash())
print(git_tag())
print(branch_name())
|