-
Notifications
You must be signed in to change notification settings - Fork 3
/
tasks.py
108 lines (81 loc) · 2.55 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
import os
from invoke import task, call
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__)))
TO_CLEAN = ['build', 'dist', '**/*.pyc', 'reports']
def color(code):
'''A simple ANSI color wrapper factory'''
return lambda t: '\033[{0}{1}\033[0;m'.format(code, t)
green = color('1;32m')
red = color('1;31m')
blue = color('1;30m')
cyan = color('1;36m')
purple = color('1;35m')
white = color('1;39m')
def header(text):
'''Display an header'''
print(' '.join((blue('>>'), cyan(text))))
def info(text, *args, **kwargs):
'''Display informations'''
text = text.format(*args, **kwargs)
print(' '.join((purple('>>>'), text)))
def success(text):
'''Display a success message'''
print(' '.join((green('>>'), white(text))))
def error(text):
'''Display an error message'''
print(red('✘ {0}'.format(text)))
@task
def clean(ctx):
'''Cleanup all build artifacts'''
header(clean.__doc__)
with ctx.cd(ROOT):
for pattern in TO_CLEAN:
info('Removing {0}', pattern)
ctx.run('rm -rf {0}'.format(pattern))
@task
def test(ctx, report=False):
'''Run tests suite'''
cmd = 'pytest -v'
if report:
cmd = ' '.join((cmd, '--junitxml=reports/tests.xml'))
with ctx.cd(ROOT):
ctx.run(cmd, pty=True)
@task
def cover(ctx, html=False):
'''Run tests suite with coverage'''
cmd = 'pytest --cov udata_piwik --cov-report term'
if html:
cmd = ' '.join((cmd, '--cov-report html:reports/cover'))
with ctx.cd(ROOT):
ctx.run(cmd, pty=True)
@task
def qa(ctx):
'''Run a quality report'''
header(qa.__doc__)
with ctx.cd(ROOT):
info('Python Static Analysis')
flake8_results = ctx.run('flake8 udata_piwik', pty=True, warn=True)
if flake8_results.failed:
error('There is some lints to fix')
else:
success('No lint to fix')
if flake8_results.failed:
error('Quality check failed')
exit(flake8_results.return_code)
success('Quality check OK')
@task
def dist(ctx, buildno=None):
'''Package for distribution'''
header('Building a distributable package')
cmd = ['python setup.py']
if buildno:
cmd.append('egg_info -b {0}'.format(buildno))
cmd.append('bdist_wheel')
with ctx.cd(ROOT):
ctx.run(' '.join(cmd), pty=True)
ctx.run('twine check dist/*')
success('Distribution is available in dist directory')
@task(clean, qa, call(test, report=True), dist, default=True)
def default(ctx):
'''Perform quality report, tests and packaging'''
pass