https://pantsbuild.org/ logo
p

prehistoric-afternoon-67621

08/01/2022, 2:05 PM
I recently upgraded from pants 2.11 to 2.12, and I'm getting an error with my proto -> python generation. The generated python code has the following invalid import:
Copy code
from google.protobuf.internal import builder as _builder
E   ImportError: cannot import name 'builder' from 'google.protobuf.internal'
I'm using
protobuf==3.19.4
in the project. Unfortunately I have a requirement in the project that requires
protobuf<3.20
(due to Tensorflow) so I can't bump this. Anyone have any suggestions? 🙏
1
Current best guess is I need to specify a version of protoc somewhere in my pants.toml? When I generate the python code using
protoc
directly (version 3.19.4), I don't get the invalid import. So my guess is that pants 2.12 bumped the version of protoc that is used.
s

sparse-lifeguard-95737

08/01/2022, 2:19 PM
yeah, your guess is correct. we’re in a similar situation, here’s what I added to my
pants.toml
to fix it:
Copy code
[protoc]
version = "3.9.2"
# NOTE: Since we're using a non-default version of protoc, we have to specify the sha256 and size
# of the download for each platform here.
#
# Downloads are coming from:
# <https://github.com/protocolbuffers/protobuf/releases/tag/v{version}-protoc-{version}-{platform}.zip>
#
# For each download we want to support,
#   1. Download it
#   2. Use `sha256sum` to compute the sha
#   3. Use `wc -c` to compute the size
#   4. Update the table here to match
known_versions = [
    "3.9.2|linux_arm64 |55dba3d64d45fc79e4c93d376b2e578dfec913eaa2b6f071beb2460956a17db6|1443656",
    "3.9.2|linux_x86_64|0d9034a3b02bd77edf5ef926fb514819a0007f84252c5e6a6391ddfc4189b904|1556020",
    "3.9.2|macos_arm64 |f02de67311645bbc5a05d8dfc6f7ea6fe56f0db38546cb5327d1544a798a5612|2862486",
    "3.9.2|macos_x86_64|f02de67311645bbc5a05d8dfc6f7ea6fe56f0db38546cb5327d1544a798a5612|2862486"
]
Also this, though I’m not sure if I’m just repeating the default configs here:
Copy code
[protoc.url_platform_mapping]
linux_arm64 = "linux-aarch_64"
linux_x86_64 = "linux-x86_64"
# NOTE: arm64-native protoc not available until v3.20.1, so we also download the x86_64
# binary when running on M1.
macos_arm64 = "osx-x86_64"
macos_x86_64 = "osx-x86_64"
p

prehistoric-afternoon-67621

08/01/2022, 2:20 PM
@sparse-lifeguard-95737 thanks so much Dan!
FWIW at least in my case (needed 3.19.4) I didn't need to repeat those default url platform mappings.