diff --git a/version.py b/version.py index ac64618..3092b3a 100644 --- a/version.py +++ b/version.py @@ -3,11 +3,21 @@ SPDX-FileCopyrightText: © Sebastian Thomschke and contributors SPDX-License-Identifier: AGPL-3.0-or-later SPDX-ArtifactOfProjectHomePage: https://github.com/Second-Hand-Friends/kleinanzeigen-bot/ """ -from datetime import datetime +import shutil import subprocess +from datetime import datetime, timezone # used in pyproject.toml [tool.pdm.version] def get_version() -> str: - commit_hash = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).decode().strip() - return f"{datetime.now().year}+{commit_hash}" + git = shutil.which("git") + if git is None: + raise RuntimeError("git executable not found, unable to compute version") + result = subprocess.run( # noqa: S603 running git is safe here + [git, "rev-parse", "--short", "HEAD"], + check=True, + capture_output=True, + text=True, + ) + commit_hash = result.stdout.strip() + return f"{datetime.now(timezone.utc).year}+{commit_hash}"