Improve version handling

This commit is contained in:
Thomas Sileo 2022-08-24 09:02:20 +02:00
parent 6475714369
commit 3b767eae11
3 changed files with 18 additions and 8 deletions

View file

@ -14,6 +14,7 @@ from itsdangerous import URLSafeTimedSerializer
from loguru import logger from loguru import logger
from app.utils.emoji import _load_emojis from app.utils.emoji import _load_emojis
from app.utils.version import get_version_commit
ROOT_DIR = Path().parent.resolve() ROOT_DIR = Path().parent.resolve()
@ -24,7 +25,7 @@ VERSION_COMMIT = "dev"
try: try:
from app._version import VERSION_COMMIT # type: ignore from app._version import VERSION_COMMIT # type: ignore
except ImportError: except ImportError:
pass VERSION_COMMIT = get_version_commit()
# Force reloading cache when the CSS is updated # Force reloading cache when the CSS is updated
CSS_HASH = "none" CSS_HASH = "none"

12
app/utils/version.py Normal file
View file

@ -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"

View file

@ -1,6 +1,5 @@
import asyncio import asyncio
import io import io
import subprocess
import tarfile import tarfile
from contextlib import contextmanager from contextlib import contextmanager
from pathlib import Path from pathlib import Path
@ -164,14 +163,12 @@ def stats(ctx):
@contextmanager @contextmanager
def embed_version() -> Generator[None, None, None]: def embed_version() -> Generator[None, None, None]:
from app.utils.version import get_version_commit
version_file = Path("app/_version.py") version_file = Path("app/_version.py")
version_file.unlink(missing_ok=True) version_file.unlink(missing_ok=True)
version = ( version_commit = get_version_commit()
subprocess.check_output(["git", "rev-parse", "--short=8", "v2"]) version_file.write_text(f'VERSION_COMMIT = "{version_commit}"')
.split()[0]
.decode()
)
version_file.write_text(f'VERSION_COMMIT = "{version}"')
try: try:
yield yield
finally: finally: