-
Notifications
You must be signed in to change notification settings - Fork 0
/
tasks.py
57 lines (46 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
from invoke import task
from invoke.context import Context as C
from typing import Optional
import sys
sys.path.append("./build/py")
from build.py import media_channel_pb2 as media_channel
proto_message_names = {
"media-channel": media_channel.DESCRIPTOR.message_types_by_name.keys()
}
@task
def gen_proto_message(c: C, proto: str, message: str):
if proto not in proto_message_names:
raise ValueError(f"unknown proto: {proto}")
if message not in proto_message_names[proto]:
raise ValueError(f"unknown proto message: {proto}.{message}")
print(f"generating schema for {proto}.{message}")
c.run(
" ".join(
[
"protoc",
"--plugin=protoc-gen-jsonschema=./bin/protoc-gen-jsonschema",
"--jsonschema_out=./dist/schemas",
f"--jsonschema_opt=entrypoint_message={message}",
f"--jsonschema_opt=output_file_suffix=.{message}.schema.json",
"-I ./third_party/protoc-gen-jsonschema",
"-I ./src",
f"./src/{proto}.proto",
]
)
)
@task
def gen_all_messages(c: C, proto: str):
for message in proto_message_names[proto]:
gen_proto_message(c, proto, message)
@task
def gen_all_protos(c: C):
for proto in proto_message_names.keys():
gen_all_messages(c, proto)
@task
def gen(c: C, proto: Optional[str] = None, message: Optional[str] = None):
if proto is None:
gen_all_protos(c)
elif message is None:
gen_all_messages(c, proto)
else:
gen_proto_message(c, proto, message)