Make build files compatible with muon
[tinc] / version.py
index 3213e32..85f3b71 100755 (executable)
@@ -1,17 +1,9 @@
 #!/usr/bin/env python3
 
-"""Print current tinc version for using in build scripts.
-
-First try to determine the latest version using git tags. If this fails (because
-the .git directory is missing, git is not installed, or for some other reason),
-fall back to using the VERSION file. If it is not present or could not be read,
-use 'unknown'.
-"""
+"""Print current tinc version for using in build scripts."""
 
 from os import path, environ
-from sys import argv, stderr
 import subprocess as subp
-import typing as T
 
 PREFIX = "release-"
 SOURCE_ROOT = path.dirname(path.realpath(__file__))
@@ -27,25 +19,6 @@ cmd = [
     "--match=" + PREFIX + "*",
 ]
 
-if "short" in argv:
-    cmd.append("--abbrev=0")
-
-version: T.Optional[str] = None
-
-try:
-    result = subp.run(cmd, stdout=subp.PIPE, encoding="utf-8", check=False)
-    if not result.returncode:
-        version = result.stdout
-except FileNotFoundError:
-    pass
-
-if not version:
-    try:
-        with open(path.join(SOURCE_ROOT, "VERSION"), "r", encoding="utf-8") as f:
-            version = f.read().strip()
-    except OSError as e:
-        print("could not read version from file", e, file=stderr)
-elif version.startswith(PREFIX):
-    version = version[len(PREFIX) :].strip()
-
-print(version if version else "unknown", end="")
+result = subp.run(cmd, stdout=subp.PIPE, encoding="utf-8", check=True)
+version = result.stdout.strip().removeprefix("release-")
+print(version)