-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasks.py
74 lines (50 loc) · 1.58 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
from invoke import task
import os
PI = "python"
APP = "./app"
HOST = "0.0.0.0"
PORT = 5000
ENTRYPOINT = "wsgi:app"
PROD_WORKERS = 4
"""
Project task commands: Tasks can be executed using command `invoke <task-name>`
Example: invoke dev
"""
@task
def dev(c, docs=False) -> None:
c.run(f"dotenv flask --app {ENTRYPOINT} run --host={HOST} --port={PORT} --debug")
@task
def prod(c, docs=False) -> None:
c.run(f"gunicorn {ENTRYPOINT} --workers {PROD_WORKERS} --bind {HOST}:{PORT} --log-level info")
@task
def shell(c, docs=False) -> None:
c.run(f"dotenv flask --app {ENTRYPOINT} shell")
@task
def dbinit(c, docs=False) -> None:
c.run(f"dotenv flask --app {ENTRYPOINT} db init")
@task
def dbmigrate(c, docs=False) -> None:
print("Generating migrations")
c.run(f"dotenv flask --app {ENTRYPOINT} db migrate")
print("\n\nApplying migrations")
c.run(f"dotenv flask --app {ENTRYPOINT} db upgrade")
@task
def secret(c, docs=False) -> None:
c.run(f"{PI} {APP}/scripts/generate_secret.py")
@task
def test(c, docs=False) -> None:
c.run(f"dotenv {PI} -m unittest {APP}/**/test_*.py")
@task
def fmt(c, docs=False) -> None:
c.run(f"{PI} -m ruff format {APP}")
@task
def lint(c, docs=False) -> None:
c.run(f"{PI} -m ruff check {APP}")
@task
def clean(c, docs=False) -> None:
# recursively remove __pycache__ directories from project
print("Removing cache files...")
c.run("find . -type d -name '__pycache__' -exec rm -r {} +")
dist_dir = os.path.join(os.getcwd(), "dist")
if os.path.exists(dist_dir):
c.run(f"rm -rf {dist_dir}")