-
Notifications
You must be signed in to change notification settings - Fork 2
/
tasks.py
88 lines (68 loc) · 1.93 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
"""
tasks.py
--------
Project invoke tasks
Available commands
invoke --list
invoke fmt
invoke sort
invoke check
"""
import invoke
TARGETS_DESCRIPTION = "Paths/directories to format. [default: . ]"
@invoke.task(help={"targets": TARGETS_DESCRIPTION})
def sort(ctx, targets="."):
"""Sort module imports."""
print("sorting imports ...")
args = ["isort", "-rc", "--atomic", targets]
ctx.run(" ".join(args))
@invoke.task(pre=[sort], help={"targets": TARGETS_DESCRIPTION})
def fmt(ctx, targets="."):
"""Format python source code & sort imports."""
print("formatting ...")
args = ["black", targets]
ctx.run(" ".join(args))
@invoke.task
def check(ctx, fmt=False, sort=False, diff=False): # pylint: disable=redefined-outer-name
"""Check code format and import order."""
if not any([fmt, sort]):
fmt = True
sort = True
fmt_args = ["black", "--check", "."]
sort_args = ["isort", "-rc", "--check", "."]
if diff:
fmt_args.append("--diff")
sort_args.append("--diff")
cmd_args = []
if fmt:
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 lint(ctx):
"""Run linter."""
ctx.run(" ".join(["pylint", "app"]))
@invoke.task
def test(ctx):
"""Run pytest tests."""
ctx.run(" ".join(["pytest", "-v"]))
@invoke.task
def generate_reqs(ctx):
"""Generate requirements.txt"""
reqs = ["pipenv lock -r > requirements.txt", "pipenv lock -r --dev > requirements-dev.txt"]
[ctx.run(req) for req in reqs]
@invoke.task
def schedule(ctx):
"""Schedule"""
ctx.run(" ".join(["python", "tasks/schedule.py"]))
@invoke.task
def scraping(ctx):
"""Scraping."""
ctx.run(" ".join(["python", "tasks/scraping.py"]))
@invoke.task
def export(ctx):
"""Export csv"""
ctx.run(" ".join(["python", "tasks/export_csv.py"]))