Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow using python -m grpc_tools.protoc in lieu of protoc #1056

Open
yhtang opened this issue Oct 24, 2024 · 2 comments
Open

Allow using python -m grpc_tools.protoc in lieu of protoc #1056

yhtang opened this issue Oct 24, 2024 · 2 comments

Comments

@yhtang
Copy link

yhtang commented Oct 24, 2024

Thank you for creating this valuable package!

Currently, protol's protoc command relies on system calls to the protoc executable. Since protoc is not available as a PyPI package, this creates challenges for Python projects that manage dependencies exclusively via pip. While the grpcio-tools package provides protoc functionality, it can only be accessed through python -m grpc_tools.protoc.

Would it be possible to add an option to allow users to specify how protoc is invoked?

@mtralka
Copy link

mtralka commented Dec 7, 2024

For anyone looking for a workaround, we can control the protoc executable path through --protoc-path so we have some access to get around this.

protoc-shim.sh - ensure executable

#!/bin/bash
python3 -m grpc_tools.protoc "$@"

Example protol command

protol \
	--create-package \
	--in-place \
	--python-out ./helloworld \
	protoc --proto-path=./protos helloworld.proto --protoc-path /protoc-shim.sh

I'm sure there are other ways but this was a quick mitigation sufficient for my needs.

@cpascual
Copy link

Thanks @mtralka for the workaround.

As a slightly simpler solution, you can avoid creating the shim by simply using

--protoc-path "python3 -m grpc_tools.protoc"

, as in e.g.:

protol \
	--create-package \
	--in-place \
	--python-out ./helloworld \
	protoc --proto-path=./protos helloworld.proto --protoc-path "python3 -m grpc_tools.protoc"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants