e.g. in a java project
myapp
└── src
└── main
└── proto
└── com
└── abc
└── myapp
└── api
├── common.proto
└── myapp.proto
$ cat myapp/src/main/proto/com/abc/myapp/api/common.proto
syntax = "proto3";
package com.abc.myapp.api;
message Metadata {
string key = 1;
}
$ cat myapp/src/main/proto/com/abc/myapp/api/myapp.proto
syntax = "proto3";
import "com/abc/myapp/api/common.proto";
package com.abc.myapp.api;
message Request {
string name = 1;
Metadata metada = 2;
}
when compiling the protos into python modules
$ protoc -I myapp/src/main/proto --python_out=tmp com/abc/myapp/api/common.proto
$ protoc -I myapp/src/main/proto --python_out=tmp com/abc/myapp/api/myapp.proto
the output structure is like
tmp
└── com
└── abc
└── myapp
└── api
├── common_pb2.py
└── myapp_pb2.py
and inside myapp_pb2.py
, the import is very nested and like
from com.abc.myapp.api import common_pb2 as com_dot_abc_dot_myapp_dot_api_dot_common__pb2
Is there a recommended practice to make the compiled pb2 files flat in structure? e.g.
tmp
├── common_pb2.py
└── myapp_pb2.py
and myapp_pb2.py
has import like
from . import common_pb2 as ...
instead of
from com.abc.myapp.api import common_pb2 com.abc.myapp.api ...