Skip to content

Commit b83c3e6

Browse files
committed
fix: py_proto_library: external runfiles
Previously, the import path within the runfiles was only correct for the case --legacy_external_runfiles=True (which copied the runfiles into `$RUNFILES/<main repo>/external/<external repo>/<path>` in addition to `$RUNFILES/<external repo>/<path>`. This flag was flipped to False in Bazel 8.0.0. Fixes #2515. Added a regression test, and tested locally against the minimal reproducer in that issue.
1 parent 66a8b5b commit b83c3e6

File tree

11 files changed

+68
-2
lines changed

11 files changed

+68
-2
lines changed

.bazelignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ examples/bzlmod/other_module/bazel-bin
1818
examples/bzlmod/other_module/bazel-other_module
1919
examples/bzlmod/other_module/bazel-out
2020
examples/bzlmod/other_module/bazel-testlogs
21+
examples/bzlmod/py_proto_library/foo_external
2122
examples/bzlmod_build_file_generation/bazel-bzlmod_build_file_generation
2223
examples/multi_python_versions/bazel-multi_python_versions
2324
examples/pip_parse/bazel-pip_parse

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Unreleased changes template.
7070
* (pypi) Using {bzl:obj}`pip_parse.experimental_requirement_cycles` and
7171
{bzl:obj}`pip_parse.use_hub_alias_dependencies` together now works when
7272
using WORKSPACE files.
73+
* (py_proto_library) Fix import paths in Bazel 8.
7374

7475
[pep-695]: https://peps.python.org/pep-0695/
7576

examples/bzlmod/.bazelignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
other_module
2+
py_proto_library/foo_external

examples/bzlmod/MODULE.bazel

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,5 +272,11 @@ local_path_override(
272272
path = "other_module",
273273
)
274274

275+
bazel_dep(name = "foo_external", version = "")
276+
local_path_override(
277+
module_name = "foo_external",
278+
path = "py_proto_library/foo_external",
279+
)
280+
275281
# example test dependencies
276282
bazel_dep(name = "rules_shell", version = "0.3.0", dev_dependency = True)

examples/bzlmod/py_proto_library/BUILD.bazel

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
load("@bazel_skylib//rules:native_binary.bzl", "native_test")
12
load("@rules_python//python:py_test.bzl", "py_test")
23

34
py_test(
@@ -16,3 +17,12 @@ py_test(
1617
"//py_proto_library/example.com/another_proto:message_proto_py_pb2",
1718
],
1819
)
20+
21+
# Regression test for https://github.com/bazelbuild/rules_python/issues/2515
22+
#
23+
# This test failed before https://github.com/bazelbuild/rules_python/pull/2516
24+
# when ran with --legacy_external_runfiles=False (default in Bazel 8.0.0).
25+
native_test(
26+
name = "external_import_test",
27+
src = "@foo_external//:py_binary_with_proto",
28+
)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
load("@rules_python//python:proto.bzl", "py_proto_library")
3+
load("@rules_python//python:py_binary.bzl", "py_binary")
4+
5+
package(default_visibility = ["//visibility:public"])
6+
7+
proto_library(
8+
name = "proto_lib",
9+
srcs = ["nested/foo/my_proto.proto"],
10+
strip_import_prefix = "/nested/foo",
11+
)
12+
13+
py_proto_library(
14+
name = "a_proto",
15+
deps = [":proto_lib"],
16+
)
17+
18+
py_binary(
19+
name = "py_binary_with_proto",
20+
srcs = ["py_binary_with_proto.py"],
21+
deps = [":a_proto"],
22+
)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module(
2+
name = "foo_external",
3+
version = "0.0.1",
4+
)
5+
6+
bazel_dep(name = "rules_python", version = "1.0.0")
7+
bazel_dep(name = "protobuf", version = "28.2", repo_name = "com_google_protobuf")
8+
bazel_dep(name = "rules_proto", version = "7.0.2")

examples/bzlmod/py_proto_library/foo_external/WORKSPACE

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
syntax = "proto3";
2+
3+
package my_proto;
4+
5+
message MyMessage {
6+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import sys
2+
3+
if __name__ == "__main__":
4+
import my_proto_pb2
5+
sys.exit(0)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy