version.py
 1  import subprocess  # noqa: S404
 2  from collections import namedtuple
 3  
 4  
 5  Version = namedtuple("Version", ["commit", "branch", "description"])
 6  
 7  cmd = "(git rev-parse HEAD && (git symbolic-ref --short HEAD || echo) && git describe --tags --always) 2> /dev/null"
 8  
 9  
10  def get_version() -> Version:
11      return Version(*subprocess.getoutput(cmd + " || cat VERSION").splitlines())
12  
13  
14  if __name__ == "__main__":
15      print(subprocess.getoutput(cmd + " | tee VERSION"))