def METHOD_NAME(prefix, git_dir):
    check_dir = git_dir or CWD
    try:
        tags_result = subprocess.check_output(
            ['git', 'describe', '--tags', '--abbrev=0', '--match=' + prefix + '*'],
            cwd=check_dir)
    except subprocess.CalledProcessError:
        # This happens if a tag for the project didn't exist. This might be because
        # this is a new project that hasn't been tagged yet; it also might be because
        # this is being run outside the git repo, or possibly the repo was pulled
        # without its tags. We'll print an error (to stderr, since this is called as
        # a shell program by make and printing it to stdout would get captured).
        sys.stderr.write(
            'Could not find tag in {check_dir} matching {prefix} '.format(
                check_dir=check_dir, prefix=prefix)
            + '- build before release or no tags. Using 0.0.0-dev\n')
        tags_result = prefix.encode('utf-8') + b'0.0.0-dev'
    tags_matching = tags_result.strip().split(b'\n')
    return tags_matching[-1].decode('utf-8')