forked from Second-Hand-Friends/kleinanzeigen-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversion.py
More file actions
23 lines (21 loc) · 772 Bytes
/
version.py
File metadata and controls
23 lines (21 loc) · 772 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"""
SPDX-FileCopyrightText: © Sebastian Thomschke and contributors
SPDX-License-Identifier: AGPL-3.0-or-later
SPDX-ArtifactOfProjectHomePage: https://github.com/Second-Hand-Friends/kleinanzeigen-bot/
"""
import shutil
import subprocess
from datetime import datetime, timezone
# used in pyproject.toml [tool.pdm.version]
def get_version() -> str:
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}"