File: check_version.py

package info (click to toggle)
isospec 2.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,476 kB
  • sloc: cpp: 9,530; python: 2,095; makefile: 180; ansic: 100; sh: 88
file content (30 lines) | stat: -rw-r--r-- 1,103 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import subprocess
import sys

def git_version():
    version = subprocess.check_output(
        ["git", "describe", "--tags", "--abbrev=0"],
        stderr=subprocess.STDOUT
    ).strip().decode('utf-8')
    return version

def pyproject_version():
    try:
        import tomllib
        with open("pyproject.toml", "rb") as f:
            pyproject_data = tomllib.load(f)
        version = pyproject_data["project"]["version"]
        return version
    except ImportError:
        # primitive parsing for Python < 3.11
        with open("pyproject.toml", "r", encoding="utf-8") as f:
            for line in f:
                if line.strip().startswith("version ="):
                    version = line.split("=", 1)[1].strip().strip('"').strip("'")
                    return version
    raise RuntimeError("Could not determine version from pyproject.toml")

if __name__ == "__main__":
    assert git_version() == "v"+pyproject_version(), \
        f"Version mismatch: git version '{git_version()}' != pyproject.toml version '{pyproject_version()}'"
    print("Version check passed:", git_version())