1
0
Fork 0
mirror of https://github.com/Findus23/acronomy.git synced 2024-09-19 15:33:45 +02:00
acronomy/acros/templatetags/version.py
2023-04-12 22:12:27 +02:00

18 lines
475 B
Python

from pathlib import Path
from subprocess import run
from django import template
from django.core.cache import cache
register = template.Library()
@register.simple_tag
def commit_id():
current_dir = Path(__file__).parent
commit = cache.get("commit")
if not commit:
sp = run(["git", "rev-parse", "--verify", "HEAD"], capture_output=True, cwd=current_dir)
commit = sp.stdout.decode().strip()
cache.set("commit", commit)
return commit