Debian Codegraph @

cross-project-tests/debuginfo-tests/dexter/dex/utils/Version.py

raw
1 # DExTer : Debugging Experience Tester
2 # ~~~~~~ ~ ~~ ~ ~~
3 #
4 # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 # See https://llvm.org/LICENSE.txt for license information.
6 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 """DExTer version output."""
8
9 import os
10 from subprocess import CalledProcessError, check_output, STDOUT
11 import sys
12
13 from dex import __version__
14
15
16 def _git_version():
17 dir_ = os.path.dirname(__file__)
18 try:
19 branch = (
20 check_output(
21 ["git", "rev-parse", "--abbrev-ref", "HEAD"], stderr=STDOUT, cwd=dir_
22 )
23 .rstrip()
24 .decode("utf-8")
25 )
26 hash_ = (
27 check_output(["git", "rev-parse", "HEAD"], stderr=STDOUT, cwd=dir_)
28 .rstrip()
29 .decode("utf-8")
30 )
31 repo = (
32 check_output(
33 ["git", "remote", "get-url", "origin"], stderr=STDOUT, cwd=dir_
34 )
35 .rstrip()
36 .decode("utf-8")
37 )
38 return "[{} {}] ({})".format(branch, hash_, repo)
39 except (OSError, CalledProcessError):
40 pass
41 return None
42
43
44 def version(name):
45 lines = []
46 lines.append(" ".join([s for s in [name, __version__, _git_version()] if s]))
47 lines.append(" using Python {}".format(sys.version))
48 return "\n".join(lines)