forked from AnyLog-co/deployment-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompile.py
35 lines (28 loc) · 920 Bytes
/
compile.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
"""
The following script, compiles a protocol file to be used by AnyLog
requirements:
- grpcio-tools
command: may need to run with sudo when running in a docker volume
python3 compile.py dummy/dummy.proto
"""
import argparse
import os.path
from grpc_tools import protoc
parse = argparse.ArgumentParser()
parse.add_argument('proto_file', type=str, default=os.path.join(os.path.dirname(__file__), 'dummy', 'dummy.proto'))
args = parse.parse_args()
proto_file_path = os.path.expanduser(os.path.expandvars(args.proto_file))
proto_dir_path = os.path.dirname(proto_file_path)
if not os.path.isfile(proto_file_path):
print(f"Failed to locate protocol file {proto_file_path}")
exit(1)
# Use protoc to generate Python files
protoc.main(
(
"",
f"-I{proto_dir_path}",
f"--python_out={proto_dir_path}",
f"--grpc_python_out={proto_dir_path}",
f"{proto_file_path}",
)
)