示例#1
0
def get_git_rev_or_version():
    '''Either get the current git commit or the PyPI distribution
    Use pbr to get the package version'''
    command = ['git', 'rev-parse', 'HEAD']
    try:
        output = subprocess.check_output(  # nosec
            command, stderr=subprocess.DEVNULL)
        if isinstance(output, bytes):
            output = output.decode('utf-8')
        ver_type = 'commit'

    except subprocess.CalledProcessError:
        ver_type = 'package'
        output = VersionInfo('tern').version_string()
    return ver_type, output.split('\n').pop(0)