-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
69 lines (51 loc) · 1.78 KB
/
setup.py
File metadata and controls
69 lines (51 loc) · 1.78 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from __future__ import annotations
import shutil
from pathlib import Path
import setuptools
_PROTO_SRC = Path("submodules/tts-service-api/proto")
_STAGING = Path("_proto_staging")
_STAGING_TARGET = _STAGING / "techmo" / "tts" / "api" / "v3"
def _update_submodule(submodule_path: str) -> None:
import subprocess
if (Path(submodule_path) / ".git").exists():
return
if (
subprocess.call(
("git", "submodule", "update", "--init", "--depth", "1", "--", submodule_path)
)
!= 0
):
raise Exception(f"error: git submodule update failed for {submodule_path}")
def _protoc(*args: str) -> None:
import grpc_tools
from grpc_tools import protoc
well_known = str(Path(grpc_tools.__file__).parent / "_proto")
if (
protoc.main(
command := ("grpc_tools.protoc", f"--proto_path={well_known}") + args
)
!= 0
):
raise Exception(f"error: {command} failed")
def _build_protos() -> None:
_update_submodule("submodules/tts-service-api")
if not (_PROTO_SRC / "techmo_tts.proto").exists():
raise FileNotFoundError(
f"Proto source not found: {_PROTO_SRC / 'techmo_tts.proto'}\n"
"The 'tts-service-api' submodule is not initialised.\n"
"Run ./setup.sh first, then re-run ./install.sh."
)
shutil.rmtree(_STAGING, ignore_errors=True)
_STAGING_TARGET.mkdir(parents=True)
try:
shutil.copy(_PROTO_SRC / "techmo_tts.proto", _STAGING_TARGET)
_protoc(
f"--proto_path={_STAGING}",
"--python_out=.",
"--grpc_python_out=.",
"techmo/tts/api/v3/techmo_tts.proto",
)
finally:
shutil.rmtree(_STAGING, ignore_errors=True)
_build_protos()
setuptools.setup()