Load version info from Git. Fixes #387
This commit is contained in:
@@ -35,7 +35,7 @@ from .portal import init as init_portal
|
|||||||
from .puppet import Puppet, init as init_puppet
|
from .puppet import Puppet, init as init_puppet
|
||||||
from .sqlstatestore import SQLStateStore
|
from .sqlstatestore import SQLStateStore
|
||||||
from .user import User, init as init_user
|
from .user import User, init as init_user
|
||||||
from . import __version__
|
from .version import version, linkified_version
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import prometheus_client as prometheus
|
import prometheus_client as prometheus
|
||||||
@@ -47,8 +47,10 @@ class TelegramBridge(Bridge):
|
|||||||
name = "mautrix-telegram"
|
name = "mautrix-telegram"
|
||||||
command = "python -m mautrix-telegram"
|
command = "python -m mautrix-telegram"
|
||||||
description = "A Matrix-Telegram puppeting bridge."
|
description = "A Matrix-Telegram puppeting bridge."
|
||||||
|
repo_url = "https://github.com/tulir/mautrix-telegram"
|
||||||
real_user_content_key = "net.maunium.telegram.puppet"
|
real_user_content_key = "net.maunium.telegram.puppet"
|
||||||
version = __version__
|
version = version
|
||||||
|
markdown_version = linkified_version
|
||||||
config_class = Config
|
config_class = Config
|
||||||
matrix_class = MatrixHandler
|
matrix_class = MatrixHandler
|
||||||
state_store_class = SQLStateStore
|
state_store_class = SQLStateStore
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ def command_handler(_func: Optional[CommandHandlerFunc] = None, *, needs_auth: b
|
|||||||
class CommandProcessor(BaseCommandProcessor):
|
class CommandProcessor(BaseCommandProcessor):
|
||||||
def __init__(self, context: c.Context) -> None:
|
def __init__(self, context: c.Context) -> None:
|
||||||
super().__init__(az=context.az, config=context.config, event_class=CommandEvent,
|
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.tgbot = context.bot
|
||||||
self.bridge = context.bridge
|
self.bridge = context.bridge
|
||||||
self.az, self.config, self.loop, self.tgbot = context.core
|
self.az, self.config, self.loop, self.tgbot = context.core
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
from .get_version import git_tag, git_revision, version, linkified_version
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import setuptools
|
import setuptools
|
||||||
import glob
|
import glob
|
||||||
import mautrix_telegram
|
|
||||||
|
from mautrix_telegram.get_version import git_tag, git_revision, version, linkified_version
|
||||||
|
|
||||||
extras = {
|
extras = {
|
||||||
"speedups": ["cryptg>=0.1,<0.3", "cchardet", "aiodns", "Brotli"],
|
"speedups": ["cryptg>=0.1,<0.3", "cchardet", "aiodns", "Brotli"],
|
||||||
@@ -16,9 +17,18 @@ try:
|
|||||||
except IOError:
|
except IOError:
|
||||||
long_desc = "Failed to read README.md"
|
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(
|
setuptools.setup(
|
||||||
name="mautrix-telegram",
|
name="mautrix-telegram",
|
||||||
version=mautrix_telegram.__version__,
|
version=version,
|
||||||
url="https://github.com/tulir/mautrix-telegram",
|
url="https://github.com/tulir/mautrix-telegram",
|
||||||
|
|
||||||
author="Tulir Asokan",
|
author="Tulir Asokan",
|
||||||
|
|||||||
Reference in New Issue
Block a user