-
Notifications
You must be signed in to change notification settings - Fork 39
/
develop.py
103 lines (90 loc) · 2.9 KB
/
develop.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
import argparse
import subprocess
from dataclasses import dataclass
@dataclass
class Command:
alias: str
help_text: str
commands_list: list[str]
COMMANDS = [
Command(
alias="compile-deps",
help_text="Compile the project's dependencies",
commands_list=[
"python -m piptools compile --resolver backtracking -o requirements.txt pyproject.toml", # noqa: E501
"python -m piptools compile --extra dev --resolver backtracking -o requirements-dev.txt pyproject.toml", # noqa: E501
"rm -rf Western_Friend_website.egg-info",
],
),
Command(
alias="start-db",
help_text="Start the database",
commands_list=[
"docker compose up -d wf_postgres_service",
],
),
Command(
alias="stop-db",
help_text="Stop the database",
commands_list=[
"docker compose stop wf_postgres_service",
],
),
Command(
alias="reset-db",
help_text="Reset the database",
commands_list=[
"python manage.py reset_db --noinput -c",
"python manage.py migrate",
],
),
Command(
alias="scaffold-db",
help_text="Scaffold initial database content",
commands_list=[
"python manage.py scaffold_initial_content",
],
),
Command(
alias="install",
help_text="Install project dependencies",
commands_list=[
"pip-sync requirements.txt requirements-dev.txt",
],
),
Command(
alias="test",
help_text="Run tests",
commands_list=[
"python manage.py test",
],
),
Command(
alias="update-deps",
help_text="Update dependencies and check for issues",
commands_list=[
"pre-commit autoupdate",
"python -m pip install --upgrade pip-tools pip wheel",
"python -m piptools compile --upgrade --resolver backtracking -o requirements.txt pyproject.toml", # noqa: E501
"python -m piptools compile --extra dev --upgrade --resolver backtracking -o requirements-dev.txt pyproject.toml", # noqa: E501
"python -m pip check",
],
),
]
def run_command(command: str) -> None:
process = subprocess.run(command, shell=True, check=True)
process.check_returncode()
def run_commands(commands: list[str]) -> None:
for command in commands:
run_command(command)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Development tasks.")
subparsers = parser.add_subparsers()
for command in COMMANDS:
subparser = subparsers.add_parser(command.alias, help=command.help_text)
subparser.set_defaults(commands_list=command.commands_list)
args = parser.parse_args()
if "commands_list" in args:
run_commands(args.commands_list)
else:
parser.print_help()