Excited to be part of the gRPC community.
However, I'm actually facing some issues atm and am wondering if I'm on a completely wrong track here.
We're currently trying to move our python code-base to the experimental no-codegen API using the commodity function:
```
grpc.protos_and_services(protobuf_path)
```
However, we're currently facing the issues that protobuf files importing other protobuf files require special treatment which we addressed like this:
```
# load.py
import shutil
import grpc
import os
def get_protos_and_services(service):
file_paths = _import_proto_file(service)
pb2, pb2_grpc = grpc.protos_and_services(file_paths[0])
# need to do it this way as tempfile doesn't work
for f in file_paths:
os.remove(f)
return pb2, pb2_grpc
def _import_proto_file(service):
"""
Recursively imports all necessary protofiles
"""
file_paths = [f"{service}.proto"]
with open(file_paths[0], 'w+b') as f:
shutil.copy2(_get_absolute_protobuf_file_path(service),
f.name)
for line in f:
l = line.decode('utf-8')
if 'import "' in l:
service_to_import = l.replace(' ', '').lstrip('import"').split('.')[0]
file_paths.extend(_import_proto_file(service_to_import))
return file_paths
def _get_absolute_protobuf_file_path(service):
return os.path.dirname(os.path.abspath(__file__)) + f'/{service}.proto'
```
While this is far from elegant, it works.
Now, there's another protobuf file that has an import from the official google standard protobuf lib:
```
import "google/protobuf/timestamp.proto";
```
This case is not covered from the code above and we're currently struggling to find a solution of how to import it using the no-codegen API.