def write_version_py(filename=_VERSION_FILENAME):
    """ Create a file containing the version information. """

    template = """\
# This file was automatically generated from the `setup.py` script.
version = '{version}'
full_version = '{full_version}'
git_revision = '{git_revision}'
is_released = {is_released}

if not is_released:
    version = full_version
"""
    # Adding the git rev number needs to be done inside
    # write_version_py(), otherwise the import of _version messes
    # up the build under Python 3.
    fullversion = VERSION
    if os.path.exists('.git'):
        git_rev, dev_num = git_version()
    elif os.path.exists(filename):
        # must be a source distribution, use existing version file
        try:
            from envisage._version import git_revision as git_rev
            from envisage._version import full_version as full_v
        except __HOLE__:
            msg = ("Unable to import 'git_revision' or 'full_revision'. "
                   "Try removing {} and the build directory before building.")
            raise ImportError(msg.format(_VERSION_FILENAME))

        match = re.match(r'.*?\.dev(?P<dev_num>\d+)', full_v)
        if match is None:
            dev_num = '0'
        else:
            dev_num = match.group('dev_num')
    else:
        git_rev = 'Unknown'
        dev_num = '0'

    if not IS_RELEASED:
        fullversion += '.dev{0}'.format(dev_num)

    with open(filename, "wt") as fp:
        fp.write(template.format(version=VERSION,
                                 full_version=fullversion,
                                 git_revision=git_rev,
                                 is_released=IS_RELEASED))
dataset/ETHPy150Open enthought/envisage/setup.py/write_version_py