Coverage for src/couchers/descriptor_pool.py: 100%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

12 statements  

1import functools 

2from pathlib import Path 

3 

4from google.protobuf import descriptor_pb2, descriptor_pool 

5 

6 

7@functools.lru_cache 

8def get_descriptor_pool(): 

9 """ 

10 Generates a protocol buffer object descriptor pool which allows looking up info about our proto API, such as options 

11 for each servicer, method, or message. 

12 """ 

13 # this needs to be imported so the annotations are available in the generated pool... 

14 from proto import annotations_pb2 # noqa 

15 

16 pool = descriptor_pool.DescriptorPool() 

17 with open(Path(__file__).parent / ".." / "proto" / "descriptors.pb", "rb") as descriptor_set_f: 

18 desc = descriptor_pb2.FileDescriptorSet.FromString(descriptor_set_f.read()) 

19 for file_descriptor in desc.file: 

20 pool.Add(file_descriptor) 

21 return pool