Skip to content

Commit 56acdb2

Browse files
committed
switch to "protoc-gen-grpc-python-prebuilt" for the grpc-python-plugin
First of all, why does this exist at all? See grpc/grpc#26125 Because of that way back in #10927 we built the plugin and uploaded it to binaries.pantsbuild.org. In the intervening time the original upstream issue is unresolved, but someone did the work to put together multi-arch CI at https://github.com/nhurden/protoc-gen-grpc-python-prebuilt This gives us a more recent version and fills in the missing macos arm64 support. We could fork and host in the pantsbuild org on GitHub, but given the rate of change to grpc-python-plugin I don't think that is warranted right now. This removes one of the last things the project pays to serve from binaries.pantsbuild.org
1 parent c125567 commit 56acdb2

File tree

3 files changed

+30
-17
lines changed

3 files changed

+30
-17
lines changed

docs/notes/2.31.x.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ Added a default module mapping for `apache-airflow-client`, which provides the `
7575

7676
Upgraded the default version of `protoc` to v30.2. Python projects should upgrade the `protobuf` Python requirement to a v6.x version. Java projects should upgrade the `protobuf-java` artifact to a 4.x version.
7777

78+
The `grpc-python-plugin` tool now uses an updated `v1.73.1` plugin built from <https://github.com/nhurden/protoc-gen-grpc-python-prebuilt]. This also brings `macos_arm64` support.
79+
7880
#### Shell
7981

8082
`shell_command` targets are now runnable via the `run` goal and can be used as a "runnable" target by other targets including the `code_quality_tool` target type. The `run_shell_command` target type remains available at the moment. The difference between running a `shell_command` versus a `run_shell_command` target is that `shell_command` targets can be run within the Pants execution sandbox (and outputs captured) while the more limited execution model of the `run_shell_command` target type only supports interactive execution.
Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,37 @@
11
# Copyright 2020 Pants project contributors (see CONTRIBUTORS.md).
22
# Licensed under the Apache License, Version 2.0 (see LICENSE).
33

4-
from pants.core.util_rules.external_tool import TemplatedExternalTool
4+
from pants.core.util_rules.external_tool import ExternalTool
5+
from pants.engine.platform import Platform
56

67

7-
class GrpcPythonPlugin(TemplatedExternalTool):
8+
class GrpcPythonPlugin(ExternalTool):
89
options_scope = "grpc-python-plugin"
910
help = "The gRPC Protobuf plugin for Python."
1011

11-
default_version = "1.32.0"
12+
# https://github.com/nhurden/protoc-gen-grpc-python-prebuilt maintains a
13+
# composite versioning strategy with both the grpc plugin version and the
14+
# version of "protoc-gen-grpc-python-prebuilt" that built it
15+
default_version = "v0.2.0+v1.73.1"
1216
default_known_versions = [
13-
"1.32.0|macos_arm64 |b2db586656463841aa2fd4aab34fb6bd3ef887b522d80e4f2f292146c357f533|6215304",
14-
"1.32.0|macos_x86_64|b2db586656463841aa2fd4aab34fb6bd3ef887b522d80e4f2f292146c357f533|6215304",
15-
"1.32.0|linux_arm64 |9365e728c603d64735963074340994245d324712344f63557ef3630864dd9f52|5233664",
16-
"1.32.0|linux_x86_64|1af99df9bf733c17a75cbe379f3f9d9ff1627d8a8035ea057c3c78575afe1687|4965728",
17+
"v0.2.0+v1.73.1|linux_arm64|91da9e959553224a4f3977313b1e0ec45ba966536da28b76041e151bf218502a|13965288",
18+
"v0.2.0+v1.73.1|linux_x86_64|72d864bb3832d8f094f3c9add308724565a446cc8a19f041f8752848068b70a1|13197104",
19+
"v0.2.0+v1.73.1|macos_arm64|ea26c8b5c1a534fe271b8a2d8a2683f25d75de4d767fbf0b9e78d43a0ea228ce|33011832",
20+
"v0.2.0+v1.73.1|macos_x86_64|ea26c8b5c1a534fe271b8a2d8a2683f25d75de4d767fbf0b9e78d43a0ea228ce|33011832",
21+
# Old versions from binaries.pantsbuild.org
22+
"1.32.0|macos_arm64 |b2db586656463841aa2fd4aab34fb6bd3ef887b522d80e4f2f292146c357f533|6215304|https://binaries.pantsbuild.org/bin/grpc_python_plugin/1.32.0/macos/x86_64/grpc_python_plugin",
23+
"1.32.0|macos_x86_64|b2db586656463841aa2fd4aab34fb6bd3ef887b522d80e4f2f292146c357f533|6215304|https://binaries.pantsbuild.org/bin/grpc_python_plugin/1.32.0/macos/x86_64/grpc_python_plugin",
24+
"1.32.0|linux_arm64 |9365e728c603d64735963074340994245d324712344f63557ef3630864dd9f52|5233664|https://binaries.pantsbuild.org/bin/grpc_python_plugin/1.32.0/linux/arm64/grpc_python_plugin",
25+
"1.32.0|linux_x86_64|1af99df9bf733c17a75cbe379f3f9d9ff1627d8a8035ea057c3c78575afe1687|4965728|https://binaries.pantsbuild.org/bin/grpc_python_plugin/1.32.0/linux/x86_64/grpc_python_plugin",
1726
]
18-
default_url_template = (
19-
"https://binaries.pantsbuild.org/bin/grpc_python_plugin/{version}/"
20-
"{platform}/grpc_python_plugin"
21-
)
22-
default_url_platform_mapping = {
23-
"macos_arm64": "macos/x86_64", # TODO: Build for arm64.
24-
"macos_x86_64": "macos/x86_64",
25-
"linux_arm64": "linux/arm64",
26-
"linux_x86_64": "linux/x86_64",
27-
}
27+
28+
def generate_url(self, plat: Platform) -> str:
29+
prebuilt_version, grpc_version = self.version.split("+")
30+
plat_str = {
31+
"macos_arm64": "macos-universal",
32+
"macos_x86_64": "macos-universal",
33+
"linux_arm64": "linux-aarch64",
34+
"linux_x86_64": "linux-x86_64",
35+
}[plat.value]
36+
37+
return f"https://github.com/nhurden/protoc-gen-grpc-python-prebuilt/releases/download/{prebuilt_version}/protoc-gen-grpc-python-{plat_str}-{grpc_version}"

src/python/pants/backend/codegen/protobuf/python/rules_integration_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ def test_grpclib_plugin(rule_runner: RuleRunner) -> None:
408408
)
409409

410410

411+
@pytest.mark.platform_specific_behavior
411412
def test_all_plugins(rule_runner: RuleRunner) -> None:
412413
rule_runner.write_files(
413414
{

0 commit comments

Comments
 (0)