From a343e2f3fa529fb3b93256f749754bbf8ecb8bb1 Mon Sep 17 00:00:00 2001 From: Colin Powell Date: Wed, 11 Mar 2026 16:26:51 -0400 Subject: [PATCH] [templates] Add version and commit to footer --- vrobbler/context_processors.py | 31 +++++++++++++++++++++++++++++++ vrobbler/settings.py | 1 + vrobbler/templates/base.html | 4 ++++ 3 files changed, 36 insertions(+) create mode 100644 vrobbler/context_processors.py diff --git a/vrobbler/context_processors.py b/vrobbler/context_processors.py new file mode 100644 index 0000000..33ba399 --- /dev/null +++ b/vrobbler/context_processors.py @@ -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} diff --git a/vrobbler/settings.py b/vrobbler/settings.py index f269f19..44b022e 100644 --- a/vrobbler/settings.py +++ b/vrobbler/settings.py @@ -183,6 +183,7 @@ TEMPLATES = [ "videos.context_processors.video_lists", "music.context_processors.music_lists", "scrobbles.context_processors.now_playing", + "vrobbler.context_processors.version_info", ], }, }, diff --git a/vrobbler/templates/base.html b/vrobbler/templates/base.html index 5d4cc6c..f8ae903 100644 --- a/vrobbler/templates/base.html +++ b/vrobbler/templates/base.html @@ -268,5 +268,9 @@ })() + +