You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to integrate protobufs with an existing codebase that's structured like
src/
python/
java/
thrift/
And I'm planning to add a src/proto3 directory. It's a bit lost as to how to make this work for the Python code since "In Python, the package directive is ignored, since Python modules are organized according to their location in the file system."
So if I wanted to generate them in a folder like /gen/proto3/python/, where the python folder is placed on the $PYTHON_PATH, a thrift file placed at src/proto3/demo/demo.proto would be turned into /gen/proto3/python/demo/demo_pb2.py (assuming I set -I src/proto3). I would have to generate __init__.py manually, which is fine, but its module path is demo.demo_pb2 rather than something like gen.proto3.demo.demo_pb2, so it'll easily run into module conflicts with stuff in src/python.
Of course I could move the protos to src/proto3/gen/proto3 instead and it'll give the desired namespace, but that's kind of... weird?
It seems like the generated code are designed to be put in the same module that the code that references them will be in, which seems like it'd require building some non-trivial tooling around so it's not cluttering the source tree.
So to summarize, I think I'm probably missing something really simple, that there's a much better way to organize this? If not, might there be an option for option python_package to specify custom module paths for Python code as well?
Thanks!
The text was updated successfully, but these errors were encountered:
TypeError: Couldn't build proto file into descriptor pool!
Invalid proto descriptor for file "annotations.proto":
annotations.proto: Import "google/api/http.proto" has not been loaded.
google.api.http: "google.api.HttpRule" seems to be defined in "http.proto", which is not imported by "annotations.proto". To use it here, please add the necessary import.
Hi,
I'm trying to integrate protobufs with an existing codebase that's structured like
And I'm planning to add a
src/proto3
directory. It's a bit lost as to how to make this work for the Python code since "In Python, the package directive is ignored, since Python modules are organized according to their location in the file system."So if I wanted to generate them in a folder like
/gen/proto3/python/
, where thepython
folder is placed on the$PYTHON_PATH
, a thrift file placed atsrc/proto3/demo/demo.proto
would be turned into/gen/proto3/python/demo/demo_pb2.py
(assuming I set-I src/proto3
). I would have to generate__init__.py
manually, which is fine, but its module path isdemo.demo_pb2
rather than something likegen.proto3.demo.demo_pb2
, so it'll easily run into module conflicts with stuff insrc/python
.Of course I could move the protos to
src/proto3/gen/proto3
instead and it'll give the desired namespace, but that's kind of... weird?It seems like the generated code are designed to be put in the same module that the code that references them will be in, which seems like it'd require building some non-trivial tooling around so it's not cluttering the source tree.
So to summarize, I think I'm probably missing something really simple, that there's a much better way to organize this? If not, might there be an option for
option python_package
to specify custom module paths for Python code as well?Thanks!
The text was updated successfully, but these errors were encountered: