-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeneratestubs.py
37 lines (31 loc) · 1.03 KB
/
generatestubs.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
from os import system
from typing import Iterable
import click
from pathlib import Path
@click.command()
@click.option(
"-d",
"--grpc-device-dir",
default="../grpc-device",
help="Root grpc-device directory to export to",
)
@click.argument("drivers", nargs=-1)
def generate_stubs(grpc_device_dir: str, drivers: Iterable[str]):
grpc_device_dir = Path("../grpc-device")
proto_source_dir = grpc_device_dir / "source/protobuf"
includes = [proto_source_dir] + [
grpc_device_dir / "generated" / driver_name for driver_name in drivers
]
include_str = str.join(" ", [f"-I{include_dir}" for include_dir in includes])
proto_files_str = str.join(
" ",
[
f"{driver_name}.proto"
for driver_name in list(drivers) + ["session", "nidevice"]
],
)
system(
rf"poetry run python -m grpc_tools.protoc {include_str} --python_out=. --grpc_python_out=. --mypy_out=. --mypy_grpc_out=. {proto_files_str}"
)
if __name__ == "__main__":
generate_stubs()