From 60bc529e4b1cfa59e82ede102b88fca08f8f93b4 Mon Sep 17 00:00:00 2001 From: Leon Sandøy Date: Sat, 22 Aug 2020 02:04:44 +0200 Subject: Move git SHA initialization to __init__.py. This will make it easier to use in multiple places. --- pydis_site/__init__.py | 5 +++++ pydis_site/context_processors.py | 6 ++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pydis_site/__init__.py b/pydis_site/__init__.py index df67cf71..f0702577 100644 --- a/pydis_site/__init__.py +++ b/pydis_site/__init__.py @@ -1,3 +1,4 @@ +import git from wiki.plugins.macros.mdx import toc # Remove the toc header prefix. There's no option for this, so we gotta monkey patch it. @@ -7,3 +8,7 @@ toc.HEADER_ID_PREFIX = '' # by a string because Allauth won't let us just give it a list _there_, we have to point # at a list _somewhere else_ instead. VALIDATORS = [] + +# Git SHA +repo = git.Repo(search_parent_directories=True) +GIT_SHA = repo.head.object.hexsha diff --git a/pydis_site/context_processors.py b/pydis_site/context_processors.py index 4ae0dbb3..bb66f21d 100644 --- a/pydis_site/context_processors.py +++ b/pydis_site/context_processors.py @@ -1,10 +1,8 @@ -import git from django.template import RequestContext -REPO = git.Repo(search_parent_directories=True) -SHA = REPO.head.object.hexsha +from pydis_site import GIT_SHA def git_sha_processor(_: RequestContext) -> dict: """Expose the git SHA for this repo to all views.""" - return {'git_sha': SHA} + return {'git_sha': GIT_SHA} -- cgit v1.2.3