-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgenerate_proto.py
More file actions
executable file
·47 lines (40 loc) · 1.36 KB
/
generate_proto.py
File metadata and controls
executable file
·47 lines (40 loc) · 1.36 KB
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
#!/usr/bin/env python3
import os
import subprocess
import sys
def generate_proto():
proto_file = "confidence/telemetry.proto"
output_dir = "confidence"
# Check if protoc is installed
try:
version = subprocess.check_output(["protoc", "--version"]).decode().strip()
print(f"Found protoc version: {version}")
except FileNotFoundError:
print("Error: protoc compiler not found. Please install it first.")
print("You can install it via:")
print(" - macOS: brew install protobuf")
print(" - Linux: apt-get install protobuf-compiler")
print(
" - Windows: Download from "
"https://github.com/protocolbuffers/protobuf/releases"
)
sys.exit(1)
# Generate Python code
cmd = [
"protoc",
f"--python_out={output_dir}",
f"--proto_path={os.path.dirname(proto_file)}",
proto_file,
]
print(f"Generating Python code from {proto_file}...")
try:
subprocess.check_call(cmd)
output_file = os.path.join(
output_dir, os.path.basename(os.path.splitext(proto_file)[0]) + "_pb2.py"
)
print(f"Successfully generated {output_file}")
except subprocess.CalledProcessError as e:
print(f"Error generating proto code: {e}")
sys.exit(1)
if __name__ == "__main__":
generate_proto()