vmagamedov / grpclib

Pure-Python gRPC implementation for asyncio
http://grpclib.readthedocs.io
BSD 3-Clause "New" or "Revised" License
936 stars 92 forks source link

Is there a wway to specify the root package? #163

Closed iot-resister closed 2 years ago

iot-resister commented 2 years ago

Currently I'm editing helloworld_grpc.py from import helloworld_pb2 to from 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!

vmagamedov commented 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

Example 2: -I /foo --python_out=/foo/bar/baz.proto

Example 3: -I / --python_out=/foo/bar/baz.proto

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.

iot-resister commented 2 years ago

thanks!