python-betterproto icon indicating copy to clipboard operation
python-betterproto copied to clipboard

overriding files with incorrect content -> package name should not be file name

Open morapet opened this issue 4 years ago • 0 comments

I feel that I use the plugin in a wrong way or there is something not designed correctly.

example:

I have directory with three files

status.proto

message Success {
}

and package svcs servicesA.proto

package svcs
import "status.proto"
service ServiceA {
... rpcs
}

service.B.proto

package svcs
import "status.proto"
service ServiceB {
... rpcs
}

running protoc 3 times (serviceA.proto, serviceB.proto status.proto) in that order:

  1. svcs.py with content of A
  2. svcs.py with content of B
  3. svcs.py with content of status.proto

I have been using protobuf for more than 12 years, but this is not correct. It is normal to have one package with multiple file being included around and similar things. the generator must either append or somehow deal with it. It is not correct expectation that each file will have a different namespace

mine current workaround - still I need to test it

     for proto_file in request.proto_file:
-        out = proto_file.package
-        if out == "google.protobuf":
+        out = proto_file.package + "." + proto_file.name.rsplit('.', 1)[0]
+        if out.startswith("google"):
             continue

morapet avatar Dec 21 '21 15:12 morapet