2021-06-18 17:57:02 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import os
|
2023-11-26 15:09:52 +01:00
|
|
|
from pathlib import Path
|
|
|
|
from subprocess import check_call
|
2021-06-18 17:57:02 +02:00
|
|
|
|
|
|
|
root_dir = Path(__file__).absolute().parent.parent
|
|
|
|
os.chdir(root_dir)
|
|
|
|
|
2024-08-29 23:15:25 +02:00
|
|
|
check_call(
|
|
|
|
[
|
|
|
|
"protoc",
|
|
|
|
"--python_out=aioesphomeapi",
|
|
|
|
"-I",
|
|
|
|
"aioesphomeapi",
|
|
|
|
"aioesphomeapi/api.proto",
|
|
|
|
"aioesphomeapi/api_options.proto",
|
|
|
|
]
|
|
|
|
)
|
2021-06-18 17:57:02 +02:00
|
|
|
|
|
|
|
# https://github.com/protocolbuffers/protobuf/issues/1491
|
2024-08-29 23:15:25 +02:00
|
|
|
api_file = root_dir / "aioesphomeapi" / "api_pb2.py"
|
2021-06-18 17:57:02 +02:00
|
|
|
content = api_file.read_text().replace(
|
|
|
|
"import api_options_pb2 as api__options__pb2",
|
2024-08-29 23:15:25 +02:00
|
|
|
"from . import api_options_pb2 as api__options__pb2",
|
2021-06-18 17:57:02 +02:00
|
|
|
)
|
|
|
|
api_file.write_text(content)
|
|
|
|
|
2024-08-29 23:15:25 +02:00
|
|
|
for fname in ["api_pb2.py", "api_options_pb2.py"]:
|
|
|
|
file = root_dir / "aioesphomeapi" / fname
|
|
|
|
content = "# type: ignore\n" + file.read_text()
|
2021-06-18 17:57:02 +02:00
|
|
|
file.write_text(content)
|