-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasks.py
88 lines (60 loc) · 1.8 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 shlex
import sys
from invoke import task # pyright: reportMissingModuleSource=false
@task
def install_deps(c):
"Install the python dependencies"
c.run("poetry install", pty=True)
@task
def setup_repository(c):
"Setup pre-commit hooks. Only needs to be done once per git checkout"
c.run("pre-commit install", pty=True)
@task
def test_reset(c):
"""
Clear caches and everything.
Shouldn't usually be necessary, try this if tdd is weird
"""
c.run("rm -rf .pytest_cache .testmondata", echo="both")
@task
def test(c):
"Run the tests"
run_with_passthrough(c, "pytest-watch -c", pty=True)
@task
def failfast(c):
"Run the tests"
run_with_passthrough(c, "pytest-watch -c -- -x", pty=True)
@task
def lint(c):
"lint with flake8"
c.run(
"flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics",
pty=True,
)
@task
def coverage(c):
"See code coverage estimations"
c.run("python -m pytest --cov=ms", pty=True)
@task
def start(c):
c.run("FLASK_ENV=development flask run", pty=True)
@task
def staging(c):
c.run("git checkout staging && git merge main && git push && git checkout main")
@task
def docs(c):
c.run(f"echo {20*'-'}")
c.run("echo 'when happy do mkdocs gh-deploy'")
c.run("mkdocs serve")
c.run(f"echo {20*'-'}")
c.run("echo 'when happy do mkdocs gh-deploy'")
#####################################################################
# Helper functions
def run_with_passthrough(c, cmd, *args, **kwargs):
return c.run(" ".join([cmd, passthrough_args()]), *args, **kwargs)
def passthrough_args() -> str:
try:
dashdash_position = sys.argv.index("--")
except ValueError:
return ""
return " ".join(map(shlex.quote, sys.argv[dashdash_position + 1 :]))