@task
def build_release():
    # To avoid dirty workdirs and various artifacts, offload complete environment
    # to temporary directory located outside of current worktree

    import os
    from subprocess import check_call, CalledProcessError
    from tempfile import mkdtemp, mkstemp

    release_clone = path(mkdtemp(prefix='paver-release-'))
    current_repo = path(os.curdir).abspath()
    branch = getattr(options, 'branch', 'master')

    # clone current branch to temporary directory
    try:
        release_clone.chdir()
        sh('git init')
        check_call(['git', 'remote', 'add', '-t', branch, '-f', 'origin', 'file://'+str(current_repo)])
        check_call(['git', 'checkout', '-b', branch, "origin/%s" % branch])

        # install release requirements to be sure we are generating everything properly
        sh('pip install -r release-requirements.txt')

        # build documentation
        sh('paver html')

        # create source directory and upload it to PyPI
        sh('paver sdist upload')

        # create wheel & update to pypi
        sh('paver bdist_wheel upload')

        # also upload sphinx documentation
        sh('paver upload_sphinx --upload-dir=paver/docs')

    finally:
        release_clone.rmtree_p()
dataset/ETHPy150Open paver/paver/pavement.py/build_release/original