From 3b767eae11d42a8841c4e91b4eba6fd8b4cbff72 Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Wed, 24 Aug 2022 09:02:20 +0200 Subject: [PATCH] Improve version handling --- app/config.py | 3 ++- app/utils/version.py | 12 ++++++++++++ tasks.py | 11 ++++------- 3 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 app/utils/version.py diff --git a/app/config.py b/app/config.py index 4e0b5ba..ba04acd 100644 --- a/app/config.py +++ b/app/config.py @@ -14,6 +14,7 @@ from itsdangerous import URLSafeTimedSerializer from loguru import logger from app.utils.emoji import _load_emojis +from app.utils.version import get_version_commit ROOT_DIR = Path().parent.resolve() @@ -24,7 +25,7 @@ VERSION_COMMIT = "dev" try: from app._version import VERSION_COMMIT # type: ignore except ImportError: - pass + VERSION_COMMIT = get_version_commit() # Force reloading cache when the CSS is updated CSS_HASH = "none" diff --git a/app/utils/version.py b/app/utils/version.py new file mode 100644 index 0000000..7b50bcb --- /dev/null +++ b/app/utils/version.py @@ -0,0 +1,12 @@ +import subprocess + + +def get_version_commit() -> str: + try: + return ( + subprocess.check_output(["git", "rev-parse", "--short=8", "v2"]) + .split()[0] + .decode() + ) + except Exception: + return "dev" diff --git a/tasks.py b/tasks.py index 4bad7dd..a2bd6f4 100644 --- a/tasks.py +++ b/tasks.py @@ -1,6 +1,5 @@ import asyncio import io -import subprocess import tarfile from contextlib import contextmanager from pathlib import Path @@ -164,14 +163,12 @@ def stats(ctx): @contextmanager def embed_version() -> Generator[None, None, None]: + from app.utils.version import get_version_commit + version_file = Path("app/_version.py") version_file.unlink(missing_ok=True) - version = ( - subprocess.check_output(["git", "rev-parse", "--short=8", "v2"]) - .split()[0] - .decode() - ) - version_file.write_text(f'VERSION_COMMIT = "{version}"') + version_commit = get_version_commit() + version_file.write_text(f'VERSION_COMMIT = "{version_commit}"') try: yield finally: