Closed iot-resister closed 2 years ago
protoc
compiler derives pythonic module name from proto-file path minus proto import path.
Example 1: -I /foo/bar --python_out=/foo/bar/baz.proto
baz.proto
; pythonic import: baz_pb2
Example 2: -I /foo --python_out=/foo/bar/baz.proto
bar/baz.proto
; pythonic import: bar.baz_pb2
Example 3: -I / --python_out=/foo/bar/baz.proto
foo/bar/baz.proto
; pythonic import: foo.bar.baz_pb2
So import path (-I
option) is the way to specify root of the package. This is also affects how imports works inside proto-files. So proto-files structure on the file system is very important for Python projects because everything is so interconnected.
thanks!
Currently I'm editing
helloworld_grpc.py
fromimport helloworld_pb2
tofrom src.proto import helloworld_pb2
to get it to work.I'm generating the files like so:
python -m grpc_tools.protoc -I. --python_out=./src/proto --grpclib_python_out=./src/proto helloworld.proto
and calling my module like so:
python -m src.server
Thanks for the awesome library!