def git_version():
    """ Parse version information from the current git commit.

    Parse the output of `git describe` and return the git hash and the number
    of commits since the last version tag.
    """

    def _minimal_ext_cmd(cmd):
        # construct minimal environment
        env = {}
        for k in ['SYSTEMROOT', 'PATH']:
            v = os.environ.get(k)
            if v is not None:
                env[k] = v
        # LANGUAGE is used on win32
        env['LANGUAGE'] = 'C'
        env['LANG'] = 'C'
        env['LC_ALL'] = 'C'
        out = subprocess.Popen(
            cmd, stdout=subprocess.PIPE, env=env,
        ).communicate()[0]
        return out

    try:
        # We ask git to find the latest tag matching a glob expression. The
        # intention is to find a release tag of the form '4.50.2'. Strictly
        # speaking, the glob expression also matches tags of the form
        # '4abc.5xyz.2gtluuu', but it's very difficult with glob expressions
        # to distinguish between the two cases, and the likelihood of a
        # problem is minimal.
        out = _minimal_ext_cmd(
            ['git', 'describe', '--match', '[0-9]*.[0-9]*.[0-9]*', '--tags'])
    except __HOLE__:
        out = ''

    git_description = out.strip().decode('ascii')
    expr = r'.*?\-(?P<count>\d+)-g(?P<hash>[a-fA-F0-9]+)'
    match = re.match(expr, git_description)
    if match is None:
        git_revision, git_count = 'Unknown', '0'
    else:
        git_revision, git_count = match.group('hash'), match.group('count')

    return git_revision, git_count
dataset/ETHPy150Open enthought/envisage/setup.py/git_version