-
Notifications
You must be signed in to change notification settings - Fork 59
/
_version.py
36 lines (25 loc) · 1.05 KB
/
_version.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# This file is part of Cachier.
# https://github.com/python-cachier/cachier
# Licensed under the MIT license:
# http:https://www.opensource.org/licenses/MIT-license
# Copyright (c) 2024, Jirka Borovec <***@gmail.com>
import os
_PATH_HERE = os.path.dirname(__file__)
_PATH_VERSION = os.path.join(_PATH_HERE, "version.info")
_RELEASING_PROCESS = os.getenv("RELEASING_PROCESS", "0") == "1"
with open(_PATH_VERSION) as fopen:
__version__ = fopen.read().strip()
def _get_git_sha() -> str:
from subprocess import DEVNULL, check_output
out = check_output(["git", "rev-parse", "--short", "HEAD"], stderr=DEVNULL) # noqa: S603, S607
return out.decode("utf-8").strip()
if not _RELEASING_PROCESS:
try:
sha_short = _get_git_sha()
# print(f"Version enriched with git commit hash: {__version__}.")
except Exception:
# print("Failed to get the git commit hash,"
# f" falling back to base version {__version__}.")
sha_short = ""
__version__ += f".dev+{sha_short}" if sha_short else ".dev"
__all__ = ["__version__"]