Skip to content

Commit 4d62f0b

Browse files
committed
chore: fix python test by using normal pip.parse
I'd rather have rules_py just unpack a wheel, but it's broken
1 parent 33a20a3 commit 4d62f0b

File tree

4 files changed

+37
-24
lines changed

4 files changed

+37
-24
lines changed

MODULE.bazel

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ bazel_dep(name = "rules_proto", version = "6.0.0-rc2")
1111
bazel_dep(name = "platforms", version = "0.0.8")
1212

1313
protoc = use_extension("//protoc:extensions.bzl", "protoc")
14-
protoc.toolchain(google_protobuf = "com_google_protobuf", version = "v25.3")
14+
protoc.toolchain(
15+
google_protobuf = "com_google_protobuf",
16+
version = "v25.3",
17+
)
1518
use_repo(protoc, "com_google_protobuf", "toolchains_protoc_hub")
1619

1720
register_toolchains("@toolchains_protoc_hub//:all")
@@ -22,7 +25,7 @@ bazel_dep(name = "aspect_rules_py", version = "0.7.1", dev_dependency = True)
2225
bazel_dep(name = "rules_java", version = "7.4.0", dev_dependency = True)
2326
bazel_dep(name = "rules_python", version = "0.31.0", dev_dependency = True)
2427

25-
# Update to include
28+
# # Update to include
2629
# https://github.com/bazelbuild/rules_python/pull/1577
2730
git_override(
2831
module_name = "rules_python",
@@ -34,3 +37,12 @@ register_toolchains(
3437
"//examples/lang_toolchains:all",
3538
dev_dependency = True,
3639
)
40+
41+
# Shows how a typical Python user fetches all the dependencies of their app, including the protobuf runtime
42+
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
43+
pip.parse(
44+
hub_name = "pypi",
45+
python_version = "3.11",
46+
requirements_lock = "//examples/lang_toolchains:requirements.txt",
47+
)
48+
use_repo(pip, "pypi")

WORKSPACE.bazel

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
# Marker that this is the root of a Bazel workspace.
22

3-
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file", "http_jar")
4-
5-
# Fetch the runtime package that applications need to marshal proto files.
6-
# This does NOT do any code generation of .pb2.py files, we still use protoc for that.
7-
# From https://pypi.org/project/protobuf/4.25.3/
8-
http_file(
9-
name = "protobuf_4_25_3",
10-
downloaded_file_path = "protobuf-4.25.3-py3-none-any.whl",
11-
sha256 = "f0700d54bcf45424477e46a9f0944155b46fb0639d69728739c0e47bab83f2b9",
12-
urls = ["https://files.pythonhosted.org/packages/f4/d5/db585a5e8d64af6b384c7b3a63da13df2ff86933e486ba78431736c67c25/protobuf-4.25.3-py3-none-any.whl"],
13-
)
3+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_jar")
144

5+
# Note: this is simpler than using rules_jvm_external with a maven installation,
6+
# but users would probably get this JAR file that way.
157
http_jar(
168
name = "protobuf-java_3_25_3",
179
sha256 = "e90d8ddb963b20a972a6a59b5093ade2b07cbe546cab3279aaf4383260385f58",

examples/lang_toolchains/BUILD

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
1-
load("@aspect_rules_py//py:defs.bzl", "py_unpacked_wheel")
21
load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain")
32

4-
# See WORKSPACE.bazel for fetch instructions of "protobuf_4_25_3".
5-
# Turn the downloaded .whl file into a py_library-shape (provides PyInfo)
6-
# Avoids the need for any pip, requirements files, python interpreter for wheel unpacking, etc
7-
py_unpacked_wheel(
8-
name = "protobuf_wheel",
9-
src = "@protobuf_4_25_3//file",
10-
py_package_name = "protobuf",
11-
)
12-
133
# Configure protoc to have the right arguments for generating Python stubs.
144
proto_lang_toolchain(
155
name = "protoc_py_toolchain",
166
command_line = "--python_out=%s",
177
progress_message = "Generating Python proto_library %{label}",
18-
runtime = ":protobuf_wheel",
8+
runtime = "@pypi//protobuf",
199
)
2010

2111
proto_lang_toolchain(
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.11
3+
# by the following command:
4+
#
5+
# bazel run //examples/lang_toolchains:requirements.update
6+
#
7+
protobuf==5.26.0 \
8+
--hash=sha256:2c334550e1cb4efac5c8a3987384bf13a4334abaf5ab59e40479e7b70ecd6b19 \
9+
--hash=sha256:6ee9d1aa02f951c5ce10bf8c6cfb7604133773038e33f913183c8b5201350600 \
10+
--hash=sha256:7e47c57303466c867374a17b2b5e99c5a7c8b72a94118e2f28efb599f19b4069 \
11+
--hash=sha256:82f5870d74c99addfe4152777bdf8168244b9cf0ac65f8eccf045ddfa9d80d9b \
12+
--hash=sha256:8eef61a90631c21b06b4f492a27e199a269827f046de3bb68b61aa84fcf50905 \
13+
--hash=sha256:a49b6c5359bf34fb7bf965bf21abfab4476e4527d822ab5289ee3bf73f291159 \
14+
--hash=sha256:ca825f4eecb8c342d2ec581e6a5ad1ad1a47bededaecd768e0d3451ae4aaac2b \
15+
--hash=sha256:dfd29f6eb34107dccf289a93d44fb6b131e68888d090b784b691775ac84e8213 \
16+
--hash=sha256:e184175276edc222e2d5e314a72521e10049938a9a4961fe4bea9b25d073c03f \
17+
--hash=sha256:efd4f5894c50bd76cbcfdd668cd941021333861ed0f441c78a83d8254a01cc9f \
18+
--hash=sha256:f9ecc8eb6f18037e0cbf43256db0325d4723f429bca7ef5cd358b7c29d65f628
19+
# via -r examples/lang_toolchains/requirements.in

0 commit comments

Comments
 (0)