File: gen-protoc

package info (click to toggle)
python-aioesphomeapi 25.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 964 kB
  • sloc: python: 10,688; sh: 8; makefile: 4
file content (26 lines) | stat: -rwxr-xr-x 783 bytes parent folder | download
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
#!/usr/bin/env python3

import os
from pathlib import Path
from subprocess import check_call

root_dir = Path(__file__).absolute().parent.parent
os.chdir(root_dir)

check_call([
    "protoc", "--python_out=aioesphomeapi", "-I", "aioesphomeapi",
    "aioesphomeapi/api.proto", "aioesphomeapi/api_options.proto"
])

# https://github.com/protocolbuffers/protobuf/issues/1491
api_file = root_dir / 'aioesphomeapi' / 'api_pb2.py'
content = api_file.read_text().replace(
    "import api_options_pb2 as api__options__pb2",
    "from . import api_options_pb2 as api__options__pb2"
)
api_file.write_text(content)

for fname in ['api_pb2.py', 'api_options_pb2.py']:
    file = root_dir / 'aioesphomeapi' / fname
    content = '# type: ignore\n' + file.read_text()
    file.write_text(content)