breezy-mouse-20493
12/16/2023, 1:50 AMprotoc
for python:
How can I have protoc make this:
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
"""Client and server classes corresponding to protobuf-defined services."""
import grpc
from . import rdu_pb2 as rdu__pb2 <-- Relative import!
...
instead of
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
"""Client and server classes corresponding to protobuf-defined services."""
import grpc
import rdu_pb2 as rdu__pb2 <--- fails!
Have looked around on the internet and it seems most suggestions involve adding this generated protobuf folder to the $PYTHONPATH. Since I'd rather not do this I'm coming here for some advice!better-van-82973
12/16/2023, 4:12 AMprotoc
output to patch in the relative import using sed
? That's probably what I would dobreezy-mouse-20493
12/16/2023, 4:15 AMbreezy-mouse-20493
12/16/2023, 4:15 AMgorgeous-winter-99296
12/16/2023, 10:02 AMsed -i -E 's/^import.*_pb2/from . \0/' $app/api/*.py
sed -i -E "s/'__module__' : '/'__module__' : '$app.api./g" $app/api/*.py
touch ./$app/api/__init__.py
So both fixing imports, module names, and adding a init.py. Had completely forgotten these hacks were even necessary 😄breezy-mouse-20493
12/16/2023, 5:32 PMlittle-pilot-11155
12/18/2023, 2:02 PMbreezy-mouse-20493
12/18/2023, 5:03 PM