forked from marshmallow-code/webargs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasks.py
109 lines (97 loc) · 3.01 KB
/
tasks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# -*- coding: utf-8 -*-
import os
import sys
import webbrowser
from invoke import task
docs_dir = 'docs'
build_dir = os.path.join(docs_dir, '_build')
@task
def test(ctx, coverage=False, browse=False):
flake(ctx)
import pytest
args = []
if coverage:
args.extend(['--cov=webargs', '--cov-report=term', '--cov-report=html'])
ignores = []
if sys.version_info < (3, 4, 1):
ignores += [
os.path.join('tests', 'test_aiohttpparser.py')
]
if sys.version_info < (3, 5, 0):
ignores += [
os.path.join('tests', 'test_aiohttpparser_async_functions.py')
]
if ignores:
for each in ignores:
args.append('--ignore={0}'.format(each))
retcode = pytest.main(args)
if coverage and browse:
webbrowser.open_new_tab(os.path.join('htmlcov', 'index.html'))
sys.exit(retcode)
@task
def flake(ctx):
"""Run flake8 on codebase."""
cmd = 'flake8 .'
excludes = []
if sys.version_info < (3, 4, 1):
excludes = [
os.path.join('tests', 'apps', 'aiohttp_app.py'),
os.path.join('tests', 'test_aiohttparser.py'),
os.path.join('webargs', 'async.py'),
os.path.join('webargs', 'async_decorators34.py'),
os.path.join('webargs', 'aiohttpparser.py'),
os.path.join('examples', 'annotations_example.py'),
'build',
]
if sys.version_info < (3, 5, 0):
excludes += [
os.path.join('webargs', 'async_decorators.py'),
os.path.join('tests', 'test_aiohttpparser_async_functions.py'),
]
if excludes:
cmd += ' --exclude={0}'.format(','.join(excludes))
ctx.run(cmd, echo=True)
@task
def clean(ctx):
ctx.run('rm -rf build')
ctx.run('rm -rf dist')
ctx.run('rm -rf webargs.egg-info')
clean_docs(ctx)
print('Cleaned up.')
@task
def readme(ctx, browse=False):
ctx.run('rst2html.py README.rst > README.html')
if browse:
webbrowser.open_new_tab('README.html')
@task
def clean_docs(ctx):
ctx.run('rm -rf %s' % build_dir)
@task
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(ctx, clean=False, browse=False, watch=False):
"""Build the docs."""
if clean:
clean_docs(ctx)
if watch:
watch_docs(ctx, browse=browse)
else:
build_docs(ctx, browse=browse)
@task
def watch_docs(ctx, browse=False):
"""Run build the docs when a file changes."""
try:
import sphinx_autobuild # noqa
except ImportError:
print('ERROR: watch task requires the sphinx_autobuild package.')
print('Install it with:')
print(' pip install sphinx-autobuild')
sys.exit(1)
ctx.run('sphinx-autobuild {0} {1} {2} -z webargs'.format(
'--open-browser' if browse else '', docs_dir, build_dir), echo=True, pty=True)