
import invoke

# Based on https://github.com/pyca/cryptography/blob/master/tasks.py


@invoke.task
def changelog(version):
    print "Version %s" % version
    print "============="
    invoke.run('git log $(git describe --tags --abbrev=0)..HEAD --format=" - %s"')

@invoke.task
def release(version):
    invoke.run("git tag -a pyuv-{0} -m \"pyuv {0} release\"".format(version))
    invoke.run("git push --tags")

@invoke.task
def upload(version):
    invoke.run("python setup.py sdist")
    invoke.run("twine upload -r pypi dist/pyuv-{0}*".format(version))



import invoke

import datetime
import re
import subprocess


cmd = 'git log $(git describe --tags --abbrev=0)..HEAD --format=" - %s" | tac'
changelog_template = 'Version %s\n=============\n\n%s\n'
tag_template = '%s - pyuv version %s\n\n%s\n'


def get_version():
    return re.search(r"""__version__\s+=\s+(?P<quote>['"])(?P<version>.+?)(?P=quote)""", open('pyuv/_version.py').read()).group('version')

@invoke.task
def changelog():
    version = get_version()
    changelog = subprocess.check_output(cmd, shell=True)
    print changelog_template % (version, changelog)

@invoke.task
def release():
    version = get_version()

    changelog = subprocess.check_output(cmd, shell=True)
    with open('ChangeLog', 'r+') as f:
        content = f.read()
        f.seek(0)
        f.write(changelog_template % (version, changelog))
        f.write(content)

    dt = datetime.datetime.utcnow().replace(microsecond=0)
    tag = tag_template % (dt, version, changelog)
    invoke.run("git tag -a pyuv-{0} -m \"{1}\"".format(version, tag))

@invoke.task
def push():
    invoke.run("git push")
    invoke.run("git push --tags")

@invoke.task
def upload():
    version = get_version()
    invoke.run("python setup.py sdist")
    invoke.run("twine upload -r pypi dist/pyuv-{0}*".format(version))


enhance release process