Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ END_UNRELEASED_TEMPLATE
dep is not added to the {obj}`py_test` target.
* (gazelle) New directive `gazelle:python_generate_proto`; when `true`,
Gazelle generates `py_proto_library` rules for `proto_library`. `false` by default.
* Note: Users must manually configure their Gazelle target to support the
proto language.
* (gazelle) New directive `gazelle:python_proto_naming_convention`; controls
naming of `py_proto_library` rules.

Expand Down
24 changes: 24 additions & 0 deletions gazelle/docs/directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,30 @@ the configured name for the `@protobuf` / `@com_google_protobuf` repo in your
`MODULE.bazel`, and otherwise falling back to `@com_google_protobuf` for
compatibility with `WORKSPACE`.

:::{note}
In order to use this, you must manually configure Gazelle to target multiple
languages. Place this in your root `BUILD.bazel` file:

```
load("@bazel_gazelle//:def.bzl", "gazelle", "gazelle_binary")

gazelle_binary(
name = "gazelle_multilang",
languages = [
"@bazel_gazelle//language/proto",
# The python gazelle plugin must be listed _after_ the proto language.
"@rules_python_gazelle_plugin//python",
],
)

gazelle(
name = "gazelle",
gazelle = "//:gazelle_multilang",
)
```
:::


For example, in a package with `# gazelle:python_generate_proto true` and a
`foo.proto`, if you have both the proto extension and the Python extension
loaded into Gazelle, you'll get something like:
Expand Down
10 changes: 9 additions & 1 deletion gazelle/python/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ gazelle_test(
name = "python_test",
srcs = ["python_test.go"],
data = [
":_gazelle_binary_with_proto",
":gazelle_binary",
],
test_dirs = glob(
Expand All @@ -90,11 +91,18 @@ gazelle_test(

gazelle_binary(
name = "gazelle_binary",
languages = [":python"],
visibility = ["//visibility:public"],
)

# Only used by testing
gazelle_binary(
name = "_gazelle_binary_with_proto",
languages = [
"@bazel_gazelle//language/proto",
":python",
],
visibility = ["//visibility:public"],
visibility = ["//visibility:private"],
)

filegroup(
Expand Down
2 changes: 1 addition & 1 deletion gazelle/python/python_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (
const (
extensionDir = "python" + string(os.PathSeparator)
testDataPath = extensionDir + "testdata" + string(os.PathSeparator)
gazelleBinaryName = "gazelle_binary"
gazelleBinaryName = "_gazelle_binary_with_proto"
)

func TestGazelleBinary(t *testing.T) {
Expand Down