Load version info from Git. Fixes #387

This commit is contained in:
Tulir Asokan
2019-11-30 20:54:54 +02:00
parent 578af19baa
commit a239ca439a
5 changed files with 67 additions and 5 deletions
+4 -2
View File
@@ -35,7 +35,7 @@ from .portal import init as init_portal
from .puppet import Puppet, init as init_puppet
from .sqlstatestore import SQLStateStore
from .user import User, init as init_user
from . import __version__
from .version import version, linkified_version
try:
import prometheus_client as prometheus
@@ -47,8 +47,10 @@ class TelegramBridge(Bridge):
name = "mautrix-telegram"
command = "python -m mautrix-telegram"
description = "A Matrix-Telegram puppeting bridge."
repo_url = "https://github.com/tulir/mautrix-telegram"
real_user_content_key = "net.maunium.telegram.puppet"
version = __version__
version = version
markdown_version = linkified_version
config_class = Config
matrix_class = MatrixHandler
state_store_class = SQLStateStore
+1 -1
View File
@@ -112,7 +112,7 @@ def command_handler(_func: Optional[CommandHandlerFunc] = None, *, needs_auth: b
class CommandProcessor(BaseCommandProcessor):
def __init__(self, context: c.Context) -> None:
super().__init__(az=context.az, config=context.config, event_class=CommandEvent,
loop=context.loop)
loop=context.loop, bridge=context.bridge)
self.tgbot = context.bot
self.bridge = context.bridge
self.az, self.config, self.loop, self.tgbot = context.core
+49
View File
@@ -0,0 +1,49 @@
import subprocess
import os
from . import __version__
cmd_env = {
"PATH": os.environ["PATH"],
"HOME": os.environ["HOME"],
"LANG": "C",
"LC_ALL": "C",
}
def run(cmd):
return subprocess.check_output(cmd, stderr=subprocess.DEVNULL, env=cmd_env)
if os.path.exists(".git"):
try:
git_revision = run(["git", "rev-parse", "HEAD"]).strip().decode("ascii")
git_revision_url = f"https://github.com/tulir/mautrix-telegram/commit/{git_revision}"
git_revision = git_revision[:8]
except (subprocess.SubprocessError, OSError):
git_revision = "unknown"
git_revision_url = None
try:
git_tag = run(["git", "describe", "--exact-match", "--tags"]).strip().decode("ascii")
git_tag_url = f"https://github.com/tulir/mautrix-telegram/releases/tag/{git_tag}"
except (subprocess.SubprocessError, OSError):
git_tag = None
git_tag_url = None
else:
git_revision = "unknown"
git_revision_url = None
git_tag = None
git_tag_url = None
if git_tag and __version__ == git_tag[1:].replace("-", ""):
version = __version__
linkified_version = f"[{version}]({git_tag_url})"
else:
if not __version__.endswith("+dev"):
__version__ += "+dev"
version = f"{__version__}@{git_revision}"
if git_revision_url:
linkified_version = f"{__version__}[@{git_revision}]({git_revision_url})"
else:
linkified_version = version
+1
View File
@@ -0,0 +1 @@
from .get_version import git_tag, git_revision, version, linkified_version
+12 -2
View File
@@ -1,6 +1,7 @@
import setuptools
import glob
import mautrix_telegram
from mautrix_telegram.get_version import git_tag, git_revision, version, linkified_version
extras = {
"speedups": ["cryptg>=0.1,<0.3", "cchardet", "aiodns", "Brotli"],
@@ -16,9 +17,18 @@ try:
except IOError:
long_desc = "Failed to read README.md"
with open("mautrix_telegram/version.py", "w") as version_file:
version_file.write(f"""# Generated in setup.py
git_tag = {git_tag!r}
git_revision = {git_revision!r}
version = {version!r}
linkified_version = {linkified_version!r}
""")
setuptools.setup(
name="mautrix-telegram",
version=mautrix_telegram.__version__,
version=version,
url="https://github.com/tulir/mautrix-telegram",
author="Tulir Asokan",