def get_version_info():
    """Get VCS info and write version info to version.py
    """
    from pycbc import _version_helper

    class vdummy(object):
        def __getattr__(self, attr):
            return ''

    # If this is a pycbc git repo always populate version information using GIT
    try:
        vinfo = _version_helper.generate_git_version_info()
    except:
        vinfo = vdummy()
        vinfo.version = '1.13.dev7'
        vinfo.release = 'False'

    with open('pycbc/version.py', 'w') as f:
        f.write("# coding: utf-8\n")
        f.write("# Generated by setup.py for PyCBC on %s.\n\n"
                % vinfo.build_date)

        # print general info
        f.write('version = \'%s\'\n' % vinfo.version)
        f.write('date = \'%s\'\n' % vinfo.date)
        f.write('release = %s\n' % vinfo.release)
        f.write('last_release = \'%s\'\n' % vinfo.last_release)

        # print git info
        f.write('\ngit_hash = \'%s\'\n' % vinfo.hash)
        f.write('git_branch = \'%s\'\n' % vinfo.branch)
        f.write('git_tag = \'%s\'\n' % vinfo.tag)
        f.write('git_author = \'%s\'\n' % vinfo.author)
        f.write('git_committer = \'%s\'\n' % vinfo.committer)
        f.write('git_status = \'%s\'\n' % vinfo.status)
        f.write('git_builder = \'%s\'\n' % vinfo.builder)
        f.write('git_build_date = \'%s\'\n' % vinfo.build_date)
        f.write('git_verbose_msg = """Version: %s\n'
                'Branch: %s\n'
                'Tag: %s\n'
                'Id: %s\n'
                'Builder: %s\n'
                'Build date: %s\n'
                'Repository status is %s"""\n' %(
                                               vinfo.version,
                                               vinfo.branch,
                                               vinfo.tag,
                                               vinfo.hash,
                                               vinfo.builder,
                                               vinfo.build_date,
                                               vinfo.status))
        f.write('from pycbc._version import *\n')
        version = vinfo.version

    from pycbc import version
    version = version.version
    return version
Get VCS info and write version info to version.py