2022-02-25 02:22:50 -05:00
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
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") and shutil.which("git"):
|
|
|
|
try:
|
|
|
|
git_revision = run(["git", "rev-parse", "HEAD"]).strip().decode("ascii")
|
|
|
|
git_revision_url = f"https://github.com/mautrix/facebook/commit/{git_revision}"
|
|
|
|
git_revision = git_revision[:8]
|
|
|
|
except (subprocess.SubprocessError, OSError):
|
|
|
|
git_revision = "unknown"
|
2022-04-11 00:40:10 -04:00
|
|
|
git_revision_url = None
|
2022-02-25 02:22:50 -05:00
|
|
|
|
|
|
|
try:
|
|
|
|
git_tag = run(["git", "describe", "--exact-match", "--tags"]).strip().decode("ascii")
|
|
|
|
except (subprocess.SubprocessError, OSError):
|
|
|
|
git_tag = None
|
|
|
|
else:
|
|
|
|
git_revision = "unknown"
|
2022-04-11 00:40:10 -04:00
|
|
|
git_revision_url = None
|
2022-02-25 02:22:50 -05:00
|
|
|
git_tag = None
|
|
|
|
|
|
|
|
git_tag_url = f"https://github.com/mautrix/facebook/releases/tag/{git_tag}" if git_tag else 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
|