-
Notifications
You must be signed in to change notification settings - Fork 1
/
tasks.py
110 lines (89 loc) · 2.91 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
110
from invoke import task
@task
def package(ctx):
'''
Package distribution to upload to PyPI
'''
ctx.run('rm -rf dist')
ctx.run('python setup.py sdist')
@task
def package_deploy(ctx):
'''
Deploy package to PyPI
'''
ctx.run('twine upload dist/*')
@task
def requirements_compile(ctx):
'''
Compile Python requirements without upgrading.
Docker images need to be rebuilt after running this (inv build).
'''
ctx.run('pip-compile requirements/base.in')
ctx.run('pip-compile requirements/doc.in')
ctx.run('pip-compile requirements/all.in')
@task
def requirements_upgrade(ctx):
'''
Compile Python requirements with upgrading.
Docker images need to be rebuilt after running this (inv build).
'''
ctx.run('pip-compile -U requirements/base.in')
ctx.run('pip-compile -U requirements/doc.in')
ctx.run('pip-compile -U requirements/all.in')
@task
def build(ctx):
'Build docker images'
ctx.run('docker-compose build')
@task
def up(ctx):
'Start up development environment'
ctx.run('docker-compose up -d')
@task
def down(ctx):
'Shut down development environment'
ctx.run('docker-compose down')
@task(down, up)
def restart(ctx):
'Restart development environment'
@task
def logs(ctx):
'Follow docker logs'
ctx.run('docker-compose logs -f')
DEFAULT_TEST_OPTS = '-s -x -vv --tb=short --color=yes'
@task(help={
'tests': 'Specify the test you want to run - e.g., tests/test_fields.py',
'opts': 'Set the options passed to pytest (default: {})'.format(DEFAULT_TEST_OPTS),
'ignore': 'Specify the tests you want to ignore - e.g., tests/test_spark_job.py',
})
def test(ctx, opts=DEFAULT_TEST_OPTS, tests='tests', ignore=None):
'Runs the test suite. User can specifiy pytest options to run specific tests.'
if ignore:
opts += ' --ignore={}'.format(ignore)
ctx.run('docker-compose run app pytest {} {}'.format(opts, tests))
@task(help={
'all': 'Run all linters (default)',
'app': 'Just run the app linter (pemi)',
'tests': 'Just run the tests linter',
'files': 'Specify files -- eg., pemi/fields.py'
})
def lint(ctx, all=False, app=False, tests=False, files=None):
'Checks code quality with pylint'
all = all or not (app or tests)
if all or app:
opts = files or 'pemi'
ctx.run('docker-compose run app pylint --rcfile pemi/.pylintrc {}'.format(opts))
if all or tests:
opts = files or 'tests'
ctx.run('docker-compose run app pylint --rcfile tests/.pylintrc {}'.format(opts))
@task
def doc_generate(ctx):
'Generates documents locally and writes to docs/_build/html'
ctx.run('docker-compose run -w /app/docs --rm app sphinx-build -E . _build/html')
@task
def ps(ctx):
'View environment containers'
ctx.run('docker-compose ps')
@task
def shell(ctx):
'Start a shell running in the app container'
ctx.run('docker-compose run --rm app /bin/bash')