[templates] Add version and commit to footer
This commit is contained in:
31
vrobbler/context_processors.py
Normal file
31
vrobbler/context_processors.py
Normal file
@ -0,0 +1,31 @@
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def version_info(request):
|
||||
PROJECT_ROOT = Path(__file__).resolve().parent.parent
|
||||
try:
|
||||
commit = (
|
||||
subprocess.check_output(
|
||||
["git", "rev-parse", "--short", "HEAD"],
|
||||
cwd=PROJECT_ROOT,
|
||||
stderr=subprocess.DEVNULL,
|
||||
)
|
||||
.decode("utf-8")
|
||||
.strip()
|
||||
)
|
||||
except (subprocess.SubprocessError, FileNotFoundError):
|
||||
commit = "unknown"
|
||||
|
||||
try:
|
||||
pyproject = PROJECT_ROOT / "pyproject.toml"
|
||||
version = "unknown"
|
||||
if pyproject.exists():
|
||||
for line in pyproject.read_text().splitlines():
|
||||
if line.startswith("version = "):
|
||||
version = line.split("=")[1].strip().strip('"')
|
||||
break
|
||||
except Exception:
|
||||
version = "unknown"
|
||||
|
||||
return {"app_version": version, "git_commit": commit}
|
||||
Reference in New Issue
Block a user