"""Optional generated protobuf import.""" from __future__ import annotations from hth_sdk.exceptions import StubsNotGenerated _STUBS_HELP = ( "Python protobuf stubs are not generated. From host/: " "python3 tools/gen_python_stubs.py " "(requires grpcio-tools). See sdk/python/hth_sdk/generated/README.md." ) def load_stubs(): try: from hth_sdk.generated.hth.api.v1 import hth_pb2, hth_pb2_grpc except ImportError as exc: raise StubsNotGenerated(_STUBS_HELP) from exc return hth_pb2, hth_pb2_grpc def stubs_available() -> bool: try: load_stubs() except StubsNotGenerated: return False return True