Skip to content

Commit

Permalink
Update invoke tasks for compat with newer versions
Browse files Browse the repository at this point in the history
Also update docs tasks
  • Loading branch information
sloria committed Mar 16, 2017
1 parent 08f563d commit cee1b87
Showing 1 changed file with 34 additions and 30 deletions.
64 changes: 34 additions & 30 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
import sys
import webbrowser

from invoke import task, run
from invoke import task

docs_dir = 'docs'
build_dir = os.path.join(docs_dir, '_build')

@task
def test(watch=False, last_failing=False):
def test(ctx, watch=False, last_failing=False):
"""Run the tests.
Note: --watch requires pytest-xdist to be installed.
"""
import pytest
flake()
flake(ctx)
args = []
if watch:
args.append('-f')
Expand All @@ -25,40 +25,44 @@ def test(watch=False, last_failing=False):
sys.exit(retcode)

@task
def flake():
def flake(ctx):
"""Run flake8 on codebase."""
run('flake8 .', echo=True)
ctx.run('flake8 .', echo=True)

@task
def clean():
run("rm -rf build")
run("rm -rf dist")
run("rm -rf aiohttp_utils.egg-info")
clean_docs()
def clean(ctx):
ctx.run("rm -rf build")
ctx.run("rm -rf dist")
ctx.run("rm -rf aiohttp_utils.egg-info")
clean_docs(ctx)
print("Cleaned up.")

@task
def clean_docs():
run("rm -rf %s" % build_dir, echo=True)
def clean_docs(ctx):
ctx.run("rm -rf %s" % build_dir)

@task
def browse_docs():
def browse_docs(ctx):
path = os.path.join(build_dir, 'index.html')
webbrowser.open_new_tab(path)

def build_docs(ctx, browse):
ctx.run("sphinx-build %s %s" % (docs_dir, build_dir), echo=True)
if browse:
browse_docs(ctx)

@task
def docs(clean=False, browse=False, watch=False):
def docs(ctx, clean=False, browse=False, watch=False):
"""Build the docs."""
if clean:
clean_docs()
run("sphinx-build %s %s" % (docs_dir, build_dir), echo=True)
if browse:
browse_docs()
clean_docs(ctx)
if watch:
watch_docs()
watch_docs(ctx, browse=browse)
else:
build_docs(ctx, browse=browse)

@task
def watch_docs():
def watch_docs(ctx, browse=False):
"""Run build the docs when a file changes."""
try:
import sphinx_autobuild # noqa
Expand All @@ -67,22 +71,22 @@ def watch_docs():
print('Install it with:')
print(' pip install sphinx-autobuild')
sys.exit(1)
run('sphinx-autobuild {0} {1} --watch {2}'.format(
docs_dir, build_dir, 'aiohttp_utils'), echo=True, pty=True)
ctx.run('sphinx-autobuild {0} {1} {2} -z aiohttp_utils'.format(
'--open-browser' if browse else '', docs_dir, build_dir), echo=True, pty=True)

@task
def readme(browse=False):
run('rst2html.py README.rst > README.html')
def readme(ctx, browse=False):
ctx.run('rst2html.py README.rst > README.html')
if browse:
webbrowser.open_new_tab('README.html')

@task
def publish(test=False):
def publish(ctx, test=False):
"""Publish to the cheeseshop."""
clean()
clean(ctx)
if test:
run('python setup.py register -r test sdist bdist_wheel', echo=True)
run('twine upload dist/* -r test', echo=True)
ctx.run('python setup.py register -r test sdist bdist_wheel', echo=True)
ctx.run('twine upload dist/* -r test', echo=True)
else:
run('python setup.py register sdist bdist_wheel', echo=True)
run('twine upload dist/*', echo=True)
ctx.run('python setup.py register sdist bdist_wheel', echo=True)
ctx.run('twine upload dist/*', echo=True)

0 comments on commit cee1b87

Please sign in to comment.