rapid-bird-79300
02/23/2022, 10:40 PMgo with
go install <http://github.com/verloop/twirpy/protoc-gen-twirpy@latest|github.com/verloop/twirpy/protoc-gen-twirpy@latest>
Is it possible to use go like this in pants via an external tool? Or would we need to install go as an external tool first and then we can install plugins with it?fast-nail-55400
02/23/2022, 10:47 PMfast-nail-55400
02/23/2022, 10:49 PMfast-nail-55400
02/23/2022, 10:51 PMrapid-bird-79300
02/23/2022, 10:52 PMPythonfast-nail-55400
02/23/2022, 10:53 PMrapid-bird-79300
02/23/2022, 10:53 PMgo for the plugin run or is it required that the host machine has go installed?fast-nail-55400
02/23/2022, 10:58 PMgo already available. We would like to return to Pants managing that but have not done that work yet. (There had been performance issues with unpacking the Go SDK in every execution sandbox.)rapid-bird-79300
02/23/2022, 11:00 PMrapid-bird-79300
02/24/2022, 1:24 AMnjgrisafi@Nicks-MacBook-Pro ~/workspace/pants-example (twirp-example)$ ./pants export-codegen ::
18:12:54.37 [INFO] Initializing scheduler...
18:12:54.67 [INFO] Scheduler initialized.
18:12:54.74 [ERROR] 1 Exception encountered:
InvalidFieldException: Unrecognized field `twirp=True` in target app:proto. Valid fields for the target type `protobuf_sources`: ['dependencies', 'description', 'grpc', 'overrides', 'python_interpreter_constraints', 'python_source_root', 'sources', 'tags'].
I'm attempting to extend the existing target ProtobufSourceTarget to add a new field for twirp. I see the option when running ./pants help protobuf_source but running any other goal results in the error above.
Example repo here for the plugin: https://github.com/njgrisafi/pants-example/tree/twirp-example
follow these docs for setup:
• https://www.pantsbuild.org/docs/target-api-extending-targets
• https://www.pantsbuild.org/docs/plugins-codegenfast-nail-55400
02/24/2022, 1:40 AMfast-nail-55400
02/24/2022, 1:41 AMProtobufSourceTarget.register_plugin_field and ProtobufSourcesGeneratorTarget.register_plugin_fieldfast-nail-55400
02/24/2022, 1:42 AMprotobuf_sources (plural), so probaly missing the second callrapid-bird-79300
02/24/2022, 1:53 AMrapid-bird-79300
02/24/2022, 1:58 AMprotobuf_source but not protobuf_source*s*rapid-bird-79300
02/24/2022, 2:00 AMdef rules() -> Iterable[Rule]:
return [
ProtobufSourceTarget.register_plugin_field(ProtobufTwirpField),
ProtobufSourcesGeneratorTarget.register_plugin_field(ProtobufTwirpField),
]rapid-bird-79300
02/24/2022, 2:01 AMrapid-bird-79300
02/24/2022, 2:10 AMrapid-bird-79300
02/24/2022, 2:20 AMrapid-bird-79300
02/24/2022, 2:25 AM*sdk.rules() to the rules listrapid-bird-79300
02/24/2022, 2:29 AM./pants export-codegen :: doesn't seem to be triggering the rule. I have set the option here: https://github.com/njgrisafi/pants-example/blob/aa75626fe1d10ebf311c49be16bf03492ed6162a/app/BUILD#L3
is there something else we need?fast-nail-55400
02/24/2022, 2:37 AMfast-nail-55400
02/24/2022, 2:38 AMfast-nail-55400
02/24/2022, 2:38 AMUnionRule is commented outrapid-bird-79300
02/24/2022, 2:39 AMrapid-bird-79300
02/24/2022, 2:39 AMfast-nail-55400
02/24/2022, 2:40 AMinput = ProtobufTwirpField should be input = ProtobufSourceFieldfast-nail-55400
02/24/2022, 2:40 AMProtobufTwirpField is just an extra field that you are registering on the targets. The GenerateSourcesRequest needs the input and output source fieldsrapid-bird-79300
02/24/2022, 2:41 AMnjgrisafi@Nicks-MacBook-Pro ~/workspace/pants-example (twirp-example)$ ./pants export-codegen ::
19:40:59.75 [INFO] Initializing scheduler...
19:41:00.44 [INFO] Scheduler initialized.
19:41:00.52 [ERROR] 1 Exception encountered:
AmbiguousCodegenImplementationsException: Multiple of the registered code generators can generate PythonSourceField from ProtobufSourceField. It is ambiguous which implementation to use.
Possible implementations:
* GeneratePythonFromProtobufRequest
* GeneratePythonFromTwirpRequestfast-nail-55400
02/24/2022, 2:43 AMpants.backend.codegen.protobuf.python backendfast-nail-55400
02/24/2022, 2:44 AMrapid-bird-79300
02/24/2022, 2:44 AMnjgrisafi@Nicks-MacBook-Pro ~/workspace/pants-example (twirp-example)$ ./pants export-codegen ::
19:43:50.95 [INFO] Initializing scheduler...
19:43:51.22 [INFO] Scheduler initialized.
19:43:51.28 [ERROR] 1 Exception encountered:
MappingError: Failed to parse ./app/BUILD:
Name 'protobuf_sources' is not defined.
If you expect to see more symbols activated in the below list, refer to <https://www.pantsbuild.org/v2.9/docs/enabling-backends> for all available backends to activate.
All registered symbols: ['_python_requirements_file', 'archive', 'docker_image', 'file', 'files', 'pants_requirement', 'pants_requirements', 'pex_binary', 'pipenv_requirements', 'poetry_requirements', 'python_artifact', 'python_distribution', 'python_requirement', 'python_requirements', 'python_source', 'python_sources', 'python_test', 'python_test_utils', 'python_tests', 'relocated_files', 'resource', 'resources', 'setup_py', 'target']
Maybe I just need to register the rule for target type, think I know how to fix thisfast-nail-55400
02/24/2022, 2:45 AMtarget_types methodfast-nail-55400
02/24/2022, 2:45 AMrapid-bird-79300
02/24/2022, 2:45 AMtwirpy originally I was thinking that this can probably be added to the existing plugin upstreamfast-nail-55400
02/24/2022, 2:46 AMfast-nail-55400
02/24/2022, 2:47 AMyeah Ideally I’d like to have the native python codegen + this additional codegen to generateyeah it might make sense for an upstream contribution to the existing codegenoriginally I was thinking that this can probably be added to the existing plugin upstreamtwirpy
fast-nail-55400
02/24/2022, 2:49 AMrapid-bird-79300
02/24/2022, 2:50 AMtwirpy is you have to have that go plugin installed for it I believerapid-bird-79300
02/24/2022, 2:51 AMpython_protobuf plugin and extend it to work with twirpy and if it works well I can create a PR to upstreamfast-nail-55400
02/24/2022, 2:51 AMfast-nail-55400
02/24/2022, 2:53 AMso it sounds like now I should just copy the existingprobably lots of copy pasta, but that would work in the meantimeplugin and extend it to work withpython_protobufand if it works well I can create a PR to upstreamtwirpy
rapid-bird-79300
02/24/2022, 2:54 AMfast-nail-55400
02/24/2022, 2:59 AMrapid-bird-79300
02/24/2022, 3:13 AMnjgrisafi@Nicks-MacBook-Pro ~/workspace/pants-example (twirp-example)$ ./pants export-codegen ::
20:11:23.01 [INFO] Initializing scheduler...
20:11:23.28 [INFO] Scheduler initialized.
20:11:23.80 [ERROR] 1 Exception encountered:
ProcessExecutionFailure: Process 'Build Go twirpy protobuf plugin for `protoc`.' failed with exit code 1.
stdout:
stderr:
go install: <http://github.com/verloop/twirpy/protoc-gen-twirpy@latest|github.com/verloop/twirpy/protoc-gen-twirpy@latest>: module lookup disabled by GOPROXY=off
Use `--no-process-cleanup` to preserve process chroots for inspection.rapid-bird-79300
02/24/2022, 3:14 AMrapid-bird-79300
02/24/2022, 3:15 AMdownload_sources_result = await Get(
ProcessResult,
GoSdkProcess(
["mod", "download", "all"],
input_digest=go_mod_digest,
output_directories=("gopath",),
description="Download Go `protoc` plugin sources.",
allow_downloads=True,
),
)rapid-bird-79300
02/24/2022, 3:30 AMrapid-bird-79300
02/24/2022, 3:32 AMallow_downloads=True, to the install on go_twirpy_plugin_build_resultrapid-bird-79300
02/24/2022, 3:39 AM./pants export-codegen :: you should now see twirp codegen in distrapid-bird-79300
02/24/2022, 3:39 AM