question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Expose a py_proto_library target for build_event_stream.proto so that way the python programs outside the Bazel repo can consume the BEP

See original GitHub issue

Description of the feature request:

Make the src/main/java/com/google/devtools/build/lib/buildeventstream/proto/build_event_stream.proto file publicly visible. Alternatively, export the file with exports_files().

What underlying problem are you trying to solve with this feature?

I have a Python tool that needs to ingest the build event stream, so I’m trying to generate a Python protobuf library for the BES.

I’m using the @com_github_grpc_grpc//py_proto_library rule as such:

py_proto_library(
    name = "build_event_stream",
    deps = ["@io_bazel//src/main/java/com/google/devtools/build/lib/buildeventstream/proto:build_event_stream_proto"],
)

However, since the proto file of interest is in an external workspace, the generated build_event_stream_proto_pb2.py file has the following content which can’t be imported:

from ...io_bazel.src.main.java.com.google.devtools.build.lib.buildeventstream.proto.build_event_stream_pb2 import *

The workaround to this is to declare a filegroup with the proto file of interest, manually build a local proto library, and then list that target as a dependency (I’ve verified that this approach works with public proto files such as @io_bazel//src/main/protobuf:extra_actions_base.proto).

# This example should work, but doesn't since build_event_stream.proto is not publicly visible

py_proto_library(
    name = "build_event_stream",
    deps = [":build_event_stream_proto"],
)

proto_library(
    name = "build_event_stream_proto",
    srcs = [":build_event_stream_proto_file"],
)

filegroup(
    name = "build_event_stream_proto_file",
    srcs = ["@io_bazel//src/main/java/com/google/devtools/build/lib/buildeventstream/proto:build_event_stream.proto"],
)

Unfortunately, this workaround does not work for this case because build_event_stream.proto is not publicly visible.

Which operating system are you running Bazel on?

Ubuntu 20.04.4 LTS

What is the output of bazel info release?

release 4.2.2

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What’s the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD ?

No response

Have you found anything relevant by searching the web?

Nothing exactly relevant, but there are a bunch of questions about which py_proto_library rule to actually use (I’ve found 3 implementations…).

Any other information, logs, or outputs that you want to share?

No response

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
haxorzcommented, Jul 20, 2022

On second thought, there’s already //src/main/java/com/google/devtools/build/lib/buildeventstream/proto:build_event_stream_java_proto with intentionally-public visibility. So that precedent makes me think we don’t need to think about setting a precedent ourselves here.

Therefore I think the proposed change is very reasonable.

1reaction
tpudlikcommented, Nov 4, 2022

I too became interested in how py_proto_library is coming along, and found it’s now a PR: https://github.com/bazelbuild/rules_python/pull/832. Looks pretty close to going in!

Read more comments on GitHub >

github_iconTop Results From Across the Web

bazelbuild/rules_python: Bazel Python Rules - GitHub
This repository is the home of the core Python rules -- py_library , py_binary ... After registration, your Python targets will use the...
Read more >
Protobufs in Python with Bazel - The Thoughtful Koala
This post shows how to build protobufs for python using the version from the protobuf team. Import Protobuf Dependency. If you haven't done...
Read more >
Bazel Tutorial: Python targets with py_library ... - YouTube
In this video we're going to be creating some python targets in Bazel. Bazel is a build tool that is very popular for...
Read more >
Why is a publicly visible Bazel ProtoBuf target 'not declared'
ERROR: Analysis of target '//proto:py' failed; build aborted. However, building the external dependency from my command line works: bazel build ...
Read more >
Python Command Line Arguments
Python command line arguments are the key to converting your programs into useful and enticing tools that are ready to be used in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found