Include tag distance and commit hash in dev versions when possible (#5664)

* Include tag distance and commit hash in dev versions when possible

* Fix test
This commit is contained in:
jack1142
2022-04-03 03:51:34 +02:00
committed by GitHub
parent febca8ccbb
commit 35f1681dc1
6 changed files with 80 additions and 11 deletions

36
redbot/_version.py Normal file
View File

@@ -0,0 +1,36 @@
def _get_version(*, ignore_installed: bool = False) -> str:
if not __version__.endswith(".dev1"):
return __version__
try:
import os
import subprocess
path = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
output = subprocess.check_output(
("git", "describe", "--tags", "--long", "--dirty"), cwd=path
)
_, count, commit, *dirty = output.decode("utf-8").strip().split("-", 3)
dirty_suffix = f".{dirty[0]}" if dirty else ""
return f"{__version__[:-1]}{count}+{commit}{dirty_suffix}"
except Exception:
# `ignore_installed` is `True` when building with setuptools.
if ignore_installed:
# we don't want any failure to raise here but we should print it
import traceback
traceback.print_exc()
else:
try:
from importlib.metadata import version
return version("Red-DiscordBot")
except Exception:
# we don't want any failure to raise here but we should print it
import traceback
traceback.print_exc()
return __version__
__version__ = "3.5.0.dev1"