forked from dvnrsn/toggle-meister
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tasks.py
88 lines (66 loc) · 1.7 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
import sys
import os
from invoke import task
# You might need the following line so that alembic can traverse
# the application properly
# export PYTHONPATH=$(pwd)
IS_TTY = False if os.getenv('DOCKER') else sys.stdout.isatty()
@task
def clean(ctx):
patterns = (
'**/*.pyc',
'**/__pycache__',
'.cache',
)
for pattern in patterns:
ctx.run("rm -rf {}".format(pattern))
@task
def lint(ctx, full=False):
if full:
ctx.run('python3 -m pylint tmeister migrate tests', pty=IS_TTY)
else:
ctx.run('python3 -m flake8 tmeister migrate tests', pty=IS_TTY)
@task(pre=[clean])
def test(ctx):
"""
test the code!
:param ctx:
:param headless:
:param coverage: use --no-coverage to skip coverage results
:param x: use -x to stop at first test
:param v: use -v to increase verbosity
:return:
"""
cmd = 'python3 -m pytest --cov tmeister'
ctx.run(cmd, env={'IS_LOCAL': 'true'})
@task
def install(ctx):
"""
install dependencies
NOT to be used in docker. Only for local dev
:param ctx:
:param docker: if this is installing in a docker container
"""
ctx.run('poetry install --no-dev', pty=IS_TTY)
@task
def serve(ctx):
ctx.run('python3 run.py', pty=IS_TTY)
@task
def migrate(ctx):
ctx.run('alembic upgrade head', pty=IS_TTY)
@task
def down(ctx, all=False):
if all:
num = 'base'
else:
num = '-1'
ctx.run('alembic downgrade ' + num, pty=IS_TTY)
@task(pre=[migrate])
def seed(ctx):
print('no seed script yet')
@task
def run(ctx):
ctx.run('python3 run.py', pty=IS_TTY)
@task
def hooks(ctx):
ctx.run('ln -sf $(pwd)/hooks/pre-commit.sh .git/hooks/pre-commit')