lenML/ChatTTS-Forge
301
1import os2import subprocess3from functools import lru_cache4 5from modules.utils import constants, hf6 7git = os.environ.get("GIT", "git")8 9 10@lru_cache()11def commit_hash():12 try:13 if hf.is_spaces_env:14 return "<hf>"15 return subprocess.check_output(16 [git, "-C", constants.ROOT_DIR, "rev-parse", "HEAD"],17 shell=False,18 encoding="utf8",19 ).strip()20 except Exception:21 return "<none>"22 23 24@lru_cache()25def git_tag():26 try:27 if hf.is_spaces_env:28 return "<hf>"29 return subprocess.check_output(30 [git, "-C", constants.ROOT_DIR, "describe", "--tags"],31 shell=False,32 encoding="utf8",33 ).strip()34 except Exception:35 try:36 37 changelog_md = os.path.join(38 os.path.dirname(os.path.dirname(__file__)), "CHANGELOG.md"39 )40 with open(changelog_md, "r", encoding="utf-8") as file:41 line = next((line.strip() for line in file if line.strip()), "<none>")42 line = line.replace("## ", "")43 return line44 except Exception:45 return "<none>"46 47 48@lru_cache()49def branch_name():50 try:51 if hf.is_spaces_env:52 return "<hf>"53 return subprocess.check_output(54 [git, "-C", constants.ROOT_DIR, "rev-parse", "--abbrev-ref", "HEAD"],55 shell=False,56 encoding="utf8",57 ).strip()58 except Exception:59 return "<none>"60 61 62if __name__ == "__main__":63 print(commit_hash())64 print(git_tag())65 print(branch_name())66 