protocolbuffers / protobuf

Protocol Buffers - Google's data interchange format
http://protobuf.dev
Other
64.42k stars 15.35k forks source link

Publishing `protoc` binaries with Pip package #17188

Open RobertoRoos opened 1 week ago

RobertoRoos commented 1 week ago

What language does this apply to?

Python

Describe the problem you are trying to solve.

Installing the protobuf compiler (protoc) on Windows doesn't have a fixed procedure, not like e.g. apt install on Linux. So if I share a Python project with a protobuf, where the user needs to generate protobuf files based on the definition, that user still needs to figure out their protoc installation.

But protobuf does have a nice Pip package, and pip packages could very well include platform specific binaries.

Describe the solution you'd like

I would suggest to either:

  1. Include protoc in the protobuf Pip package.
  2. Publish a second Pip package that only contains protoc, without actual Python code.

The downside of the first is you might conflict with the user's system install. With the second you make the Pip installed binary optional, which might be more convenient.

Describe alternatives you've considered

N.a.

Additional context

If such a Pip package exists, a Python project might contain the following in its pyproject.toml:

[tool.poetry.build]
script = "build.py"

[build-system]
requires = ["poetry-core", "protobuf-protoc"]
build-backend = "poetry.core.masonry.api"

Where build.py is a script to generate protobuf files, based on protoc. protoc is then installed only during the build step of this package. The used version would be pinned to the package specification and otherwise isolated to the Python environment being used. Moreover, using it in Python would require no action outside Python and Pip.

As a result it would work like:

python -m venv .venv
.venv/Scritps/Activate.ps1
(.venv) pip install protobuf
(.venv) protoc  # Error!
(.venv) pip install protobuf-protoc
(.venv) protoc  # Binary exists in .venv/Scripts/protoc.exe
RobertoRoos commented 1 week ago

I see there are a bunch of unofficial attempts at this already: https://pypi.org/project/protoc-wheel, https://pypi.org/project/protoc-wheel-0, https://pypi.org/project/protoc-exe

The main problem is these have no affiliation with the protobuf project, so they are not maintained and importantly, there is no guarantee they packaged the legit binaries.

RobertoRoos commented 1 week ago

In the meantime I've created a package that will download the official protoc during it's own installation: https://github.com/RobertoRoos/protobuf-protoc-exe