-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tasks.py
112 lines (83 loc) · 2.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
"""Tooling for coronavirus-us-api.
"""
import invoke
INPUT_DESCRIPTION = 'List of directories to act on. [default = "."]'
@invoke.task(help={"targets": INPUT_DESCRIPTION})
def black(ctx, targets="."):
"""Formats code with black.
Arguments:
ctx {context} -- program context execution.
Keyword Arguments:
targets {str} -- space separated list of directories (default: {'.'})
"""
print(f"Formatting code under directories: [{targets}]")
args = ["black", targets]
ctx.run(" ".join(args))
@invoke.task(help={"targets": INPUT_DESCRIPTION})
def sort(ctx, targets="."):
"""Sort imports of files listed under given directories.
Arguments:
ctx {context} -- program context execution.
Keyword Arguments:
targets {str} -- space separated list of directories (default: {'.'})
"""
print(f"Sorting imports under directories: [{targets}]")
args = ["isort", "--atomic", targets]
ctx.run(" ".join(args))
@invoke.task
def check(ctx, format=False, sort=False, diff=False):
"""Function that enforces code quality in in deployment for pipeline.
Arguments:
ctx {context} -- program context execution.
Keyword Arguments:
format {bool} -- whether to format (default: {False})
sort {bool} -- whether to sort (default: {False})
diff {bool} -- display diff for commands (default: {False})
"""
if not any([format, sort]):
format = True
sort = True
fmt_args = ["black", "--check", "."]
sort_args = ["isort", "--check", "."]
if diff:
fmt_args.append("--diff")
sort_args.append("--diff")
cmd_args = []
if format:
cmd_args.extend(fmt_args)
if sort:
if cmd_args:
cmd_args.append("&")
cmd_args.extend(sort_args)
ctx.run(" ".join(cmd_args))
@invoke.task
def precommit(ctx):
"""Runs pre-commit hook for all files using flake8, black, and isort.
Arguments:
ctx {context} -- program context execution.
"""
print("Executing pre-commit hook...")
args = ["pre-commit", "run", "--all-files"]
ctx.run(" ".join(args))
@invoke.task
def test(ctx):
"""Runs unit tests for API
Arguments:
ctx {context} -- program context execution.
"""
ctx.run(" ".join(["coverage", "run", "-m", "pytest", "-v", "./tests"]))
@invoke.task
def e2e(ctx):
"""Runs e2e tests for API
Arguments:
ctx {context} -- program context execution.
"""
ctx.run(" ".join(["python", "-m", "unittest", "-v"]))
@invoke.task
def coverage(ctx):
"""Generate detailed test coverage report and outputs HTML report.
Arguments:
ctx {context} -- program context execution.
"""
ctx.run(" ".join(["coverage", "report", "-m"]))
ctx.run(" ".join(["coverage", "html"]))