Coverage for src/couchers/descriptor_pool.py: 100%
15 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-12-20 11:53 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2025-12-20 11:53 +0000
1import functools
2from pathlib import Path
4from google.protobuf import descriptor_pb2, descriptor_pool
7@functools.cache
8def get_descriptors_pb() -> bytes:
9 with open(Path(__file__).parent / "proto" / "descriptors.pb", "rb") as descriptor_set_f:
10 return descriptor_set_f.read()
13@functools.cache
14def get_descriptor_pool() -> descriptor_pool.DescriptorPool:
15 """
16 Generates a protocol buffer object descriptor pool which allows looking up info about our proto API, such as options
17 for each servicer, method, or message.
18 """
19 # this needs to be imported so the annotations are available in the generated pool...
20 from couchers.proto import annotations_pb2 # noqa
22 pool = descriptor_pool.DescriptorPool()
23 desc = descriptor_pb2.FileDescriptorSet.FromString(get_descriptors_pb())
24 for file_descriptor in desc.file:
25 pool.Add(file_descriptor) # type: ignore[no-untyped-call]
26 return pool