X-Git-Url: https://www.tinc-vpn.org/git/browse?a=blobdiff_plain;f=version.py;h=5617cae6ae84a0aca5d807d46871947d26c83bc9;hb=refs%2Fheads%2F1.1;hp=3213e3277a3a4dac17f71a4c368bc67b4031c574;hpb=2ded4a80352dfbbd17b35ae0eafcbdc62243d574;p=tinc diff --git a/version.py b/version.py index 3213e327..5617cae6 100755 --- a/version.py +++ b/version.py @@ -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().replace("release-", "", 1) +print(version)