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

15 statements  

1import functools 

2from pathlib import Path 

3 

4from google.protobuf import descriptor_pb2, descriptor_pool 

5 

6 

7@functools.lru_cache 

8def get_descriptors_pb(): 

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

10 return descriptor_set_f.read() 

11 

12 

13@functools.lru_cache 

14def get_descriptor_pool(): 

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 proto import annotations_pb2 # noqa 

21 

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) 

26 return pool