def gen_version(do_write=True, txt=None):
    """
    Generate a version based on git tag info. This will write the
    couchbase/_version.py file. If not inside a git tree it will
    raise a CantInvokeGit exception - which is normal
    (and squashed by setup.py) if we are running from a tarball
    """

    if txt is None:
        txt = get_git_describe()

    try:
        info = VersionInfo(txt)
        vstr = info.package_version
    except MalformedGitTag:
        warnings.warn("Malformed input '{0}'".format(txt))
        vstr = '0.0.0'+txt

    if not do_write:
        print(vstr)
        return

    lines = (
        '# This file automatically generated by',
        '#    {0}'.format(__file__),
        '# at',
        '#    {0}'.format(datetime.datetime.now().isoformat(' ')),
        "__version__ = '{0}'".format(vstr)
    )
    with open(VERSION_FILE, "w") as fp:
        fp.write("\n".join(lines))
dataset/ETHPy150Open couchbase/couchbase-python-client/couchbase_version.py/gen_version/original