Skip to content

Python grpc compiler does not support same language as standard python proto compiler (missing import) #41243

@bushnell-deshaw

Description

@bushnell-deshaw

With the following demo.proto I cannot build python output using grpc_tools.protoc:

// demo.proto
edition = "2023";

import "google/protobuf/go_features.proto";

option go_package = "foo.com/demo";

option features.(pb.go).api_level = API_OPAQUE;

message Demo {
  string name = 1;
}
$ python -m grpc_tools.protoc --python_out=. --pyi_out=. --grpc_python_out=. -I. demo.proto
google/protobuf/go_features.proto: File not found.
demo.proto:4:1: Import "google/protobuf/go_features.proto" was not found or had errors.

Note that this file is supposed to be built in to the protobuf compiler.

Commenting out the import and feature setting, and it works.

Using the standard protobuf compiler works however:

$ protoc --python_out=bar demo.proto && echo OK
OK

Note that it is not adequate to say "why do you need this if you are generating python output". You need this if you want to build both Python and Go message definitions from the same source, and you need to use Go features.

Note that protobuf had a bug here (golang/protobuf#1661) which has long been fixed.

https://protobuf.com/docs/language-spec is explicit that "the compiler should be able to provide their contents".

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions