Description
What happened?
When using rules python 1.0.0-rc2 in the main repository, the module extension call to initiate the pypi repo used by the protoc-gen-validate module uses the older "name" instead of using the newer "hub_name", whilst at the same time the dependency chain resolution does not initiate its own rules_python version for protoc-gen-validate.
I tried fixing it using a patch in my root module against the MODULE.bazel of protoc-gen-validate, but it did not work, most likely because protoc-gen-validate was a transitive dependency.
Output from bazel mod tidy
:
bazel mod tidy
ERROR: in tag at https://bcr.bazel.build/modules/protoc-gen-validate/1.0.4/MODULE.bazel:64:10, unknown attribute name provided. Type 'bazel help mod' for syntax and help.
Version
Development (host) and target OS/architectures: linux, amd64
Output of bazel --version
: bazel 7.4.1
Version of relevant rules from the WORKSPACE
or MODULE.bazel
file:
bazel_dep(name = "rules_python", version = "1.0.0-rc2")
bazel_dep(name = "protobuf", version = "29.0")
bazel_dep(name = "grpc", version = "1.68.0")
bazel_dep(name = "protoc-gen-validate", version = "1.0.4") // this is introduced as a dependency by grpc
Language(s) and/or frameworks involved: python, grpc, proto
How to reproduce
I tried to keep this as minimal as possible, it seems it is not triggered before you add an actual build target, so here it is:
MODULE.bazel
bazel_dep(name = "rules_python", version = "1.0.0-rc2")
bazel_dep(name = "protobuf", version = "29.0")
bazel_dep(name = "grpc", version = "1.68.0")
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
pip.parse(
hub_name = "pypi",
python_version = "3.11",
requirements_lock = "//python:requirements.txt",
)
use_repo(pip, "pypi")
protos/BUILD.bazel
load("@grpc//bazel:python_rules.bzl", "python_grpc_library")
load("@protobuf//bazel:proto_library.bzl", "proto_library")
load("@protobuf//bazel:py_proto_library.bzl", "py_proto_library")
proto_library(
name = "greeter_proto",
srcs = ["greeter.proto"],
visibility = ["//visibility:public"],
)
py_proto_library(
name = "greeter_py_proto",
visibility = ["//visibility:public"],
deps = [":greeter_proto"],
)
python_grpc_library(
name = "greeter_py_grpc",
srcs = [":greeter_proto"],
deps = [":greeter_py_proto"],
)
protos/greeter.proto
syntax = "proto3";
package greeter;
option go_package = "github.com/molnett/the-bazel-pitch/protos/greeter";
// Greeter service provides simple greeting functionality
service Greeter {
// Greet generates a personalized greeting for the given name
rpc Greet(GreetRequest) returns (GreetResponse) {}
}
// GreetRequest contains the name to be greeted
message GreetRequest {
// Name of the person to greet
string name = 1;
}
// GreetResponse contains the greeting message
message GreetResponse {
// The greeting message
string message = 1;
}
python/BUILD.bazel
load("@pypi//:requirements.bzl", "requirement")
load("@rules_python//python:defs.bzl", "py_binary", "py_test")
py_binary(
name = "cli",
srcs = ["main.py"],
main = "main.py",
visibility = ["//visibility:public"],
deps = [
"//protos:greeter_py_grpc",
"//protos:greeter_py_proto",
requirement("grpcio"),
requirement("protobuf"),
],
)
python/main.py
import argparse
import grpc
from protos.greeter_pb2 import GreetRequest
from protos.greeter_pb2_grpc import GreeterStub
def main():
parser = argparse.ArgumentParser(description='Greeter CLI client')
parser.add_argument('--name', type=str, required=True, help='Name to greet')
args = parser.parse_args()
with grpc.insecure_channel('localhost:50051') as channel:
stub = GreeterStub(channel)
try:
response = stub.Greet(GreetRequest(name=args.name))
print(response.message)
except grpc.RpcError as e:
print(f"Error: {e.details()}")
exit(1)
if __name__ == '__main__':
main()
python/requirements.txt
grpcio==1.68.0
protobuf==5.29.0
Any other information?
I am not entirely sure where to file this bug, if it should go against the grpc repository, as they are the ones who introduce this transitive dependency, against the rules_python repository because their version compatibility setting seems wrong (it does not resolve a separate rules_python version for the protoc-gen-validate, despite my MODULE.bazel file having 1.0.0-rc2 and them having a 0.22.0 dependency) or if I should file it here? I chose here, as I suspect that this is the place easiest to fix it however.
I did fix it for now with a multiple_versions_override like this:
multiple_version_override(
module_name = "rules_python",
versions = [
"1.0.0-rc2",
"0.22.0",
],
)