File size: 945 Bytes
fc5e1f9 46f3a06 2d155ff 46f3a06 2d155ff fc5e1f9 | 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 | """アプリバージョン管理"""
from __future__ import annotations
from pathlib import Path
def _get_git_commit_hash() -> str:
"""`.git`ディレクトリを直接読んで現在のコミットハッシュ(短縮形)を取得する。
gitコマンドに依存しないため、Dockerコンテナ内でも動作する。取得できなければ空文字を返す。"""
try:
git_dir = Path(__file__).resolve().parent.parent / ".git"
head = (git_dir / "HEAD").read_text().strip()
if head.startswith("ref:"):
ref_path = git_dir / head.split(" ", 1)[1]
commit = ref_path.read_text().strip()
else:
commit = head
return commit[:7]
except OSError:
return ""
def get_display_version() -> str:
"""設定画面などに表示するバージョン文字列(gitコミットハッシュ)。"""
return _get_git_commit_hash() or "dev"
|