https://pantsbuild.org/ logo
#general
Title
# general
f

freezing-quill-50372

06/07/2022, 11:26 AM
I would like to generate Python codes for protocol buffer in version 3 with optional fields like following. Protobuf >= 3.15 supports
optional
keyword, so it should be compiled successfully (I already tried on protoc >= 3.15 and checked that it was compiled without errors)
Copy code
syntax = "proto3";

package testing;

message SomeRequest {
  string required_field = 1;
  optional int32 optional_field;
}
However, when I execute
./pantsexport-codegen ::
, it said
Explicit 'optional' labels are disallowed in the Proto3 syntax. To define 'optional' fields in Proto3, simply remove the 'optional' label, as fields are 'optional' by default.
. How to resolve it ?
Detailed settings are below.
Copy code
Pants 2.11.0
pants.toml
Copy code
[GLOBAL]
pants_version = "2.11.0"
backend_packages.add = [
  "pants.backend.python",
  "pants.backend.codegen.protobuf.python",
  "pants.backend.python.typecheck.mypy",
  "pants.backend.python.lint.flake8",
  "pants.backend.python.lint.black",
  "pants.backend.python.lint.isort",
  "pants.backend.experimental.python.lint.autoflake",
  "pants.backend.docker",
  "pants.backend.docker.lint.hadolint",
]

[python]
interpreter_constraints = [">=3.9,<3.11"]

[poetry]
interpreter_constraints = [">=3.9,<3.11"]
version = "poetry>=1.1.12,<1.2"

[python-protobuf]
mypy_plugin = true
infer_runtime_dependency = false
c

curved-television-6568

06/07/2022, 11:45 AM
You’ll want to tweak these options to select your protoc version to use: https://www.pantsbuild.org/docs/reference-protoc
Or, if you use pants 2.12.x, then the default protoc version is already 3.20.1, so should be OK out of the box.
(in pants 2.11 the default protoc version is 3.11.4)
f

freezing-quill-50372

06/07/2022, 11:47 AM
Thanks, I’ll try the option.
👍 1
9 Views