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 9import os 10from subprocess import CalledProcessError, check_output, STDOUT 11import sys 12 13from dex import __version__ 14 15 16def _git_version(): 17 dir_ = os.path.dirname(__file__) 18 try: 19 branch = (check_output( 20 ['git', 'rev-parse', '--abbrev-ref', 'HEAD'], 21 stderr=STDOUT, 22 cwd=dir_).rstrip().decode('utf-8')) 23 hash_ = check_output( 24 ['git', 'rev-parse', 'HEAD'], stderr=STDOUT, 25 cwd=dir_).rstrip().decode('utf-8') 26 repo = check_output( 27 ['git', 'remote', 'get-url', 'origin'], stderr=STDOUT, 28 cwd=dir_).rstrip().decode('utf-8') 29 return '[{} {}] ({})'.format(branch, hash_, repo) 30 except (OSError, CalledProcessError): 31 pass 32 return None 33 34 35def version(name): 36 lines = [] 37 lines.append(' '.join( 38 [s for s in [name, __version__, _git_version()] if s])) 39 lines.append(' using Python {}'.format(sys.version)) 40 return '\n'.join(lines) 41