-
-
Notifications
You must be signed in to change notification settings - Fork 617
feat(gazelle): Gazelle plugin generates py_proto_library #3057
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dougthor42
merged 45 commits into
bazel-contrib:main
from
shaldengeki:gazelle-plugin-generates-py-proto-library
Jul 15, 2025
Merged
Changes from 15 commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
c85c56f
[wip] Start work on generating py_proto_library, by creating a bunch …
shaldengeki 8b5a91b
Remove test cases that don't make any sense; py_proto_library runs on…
shaldengeki d8f9b1a
Add additional test fixtures required to run tests
shaldengeki caf5d6e
[wip] Start working on generate.go
shaldengeki b712696
Fix visibility in tests
shaldengeki 3186761
Load py_proto_library from protobuf repository, since rules_proto's c…
shaldengeki e073055
Remove unneessary code
shaldengeki aa9f4aa
Delete some more unused stuff
shaldengeki b6df17b
Update CHANGELOG.md
shaldengeki d794ac1
Have a sudden change-of-heart and call it python_generate_proto, to a…
shaldengeki cad6849
Update README.md
shaldengeki a0e4f5f
Don't repeatedly initialize a variable
shaldengeki 161cc51
Add test enforcing that unnecessary rules are removed, and change log…
shaldengeki fc7fa08
Add a tiny comment
shaldengeki ad4f3f7
Merge branch 'main' into gazelle-plugin-generates-py-proto-library
shaldengeki 4853207
Default python_generate_proto to false, and update tests
shaldengeki 9a44ef3
In README.md add details section
shaldengeki 362dea9
Plugin detects configured name for protobuf directory
shaldengeki 4e41e0e
Update Gazelle, to bring in bzlmod support
shaldengeki dc27cda
Update Gazelle, to bring in bzlmod support
shaldengeki 5ee804a
Add tests covering bzlmod & renaming functionality
shaldengeki e5fbed8
Remove unnecessary licenses
shaldengeki a2cb993
Add trailing newlines to some protobuf
shaldengeki 7c2706c
Add test covering "deletes only the py_proto_library rule"
shaldengeki 59561fc
Always run generateProtoLibraries, to ensure we run deletion logic
shaldengeki 634411c
Update WORKSPACE, too
shaldengeki 30cecf4
Merge branch 'update-gazelle' into gazelle-plugin-generates-py-proto-…
shaldengeki 1cabc18
Update shasum
shaldengeki 9a38c26
Merge branch 'main' into update-gazelle
shaldengeki aa9e24a
Use golang 1.20.5
shaldengeki 7fcc921
Merge branch 'update-gazelle' into gazelle-plugin-generates-py-proto-…
shaldengeki 3d3c302
When python_proto_generate=false, ignore any pre-existing py_proto_li…
shaldengeki 086c6aa
Merge branch 'main' into gazelle-plugin-generates-py-proto-library
shaldengeki cdeafde
Undo gazelle upgrade, and remove tests that depend on bzlmod support
shaldengeki 18f34d1
Merge branch 'main' into gazelle-plugin-generates-py-proto-library
shaldengeki 763ef9d
Wrap README.md to 80 chars per line, and be less-disruptive to existi…
shaldengeki b3805a9
Fix some language again
shaldengeki 3e0fdcc
Use _py_proto suffix, to align with java, go naming schemes
shaldengeki 0c9d436
Revert "Use _py_proto suffix, to align with java, go naming schemes"
shaldengeki eb87801
Revert "Undo gazelle upgrade, and remove tests that depend on bzlmod …
shaldengeki 6791d4b
Undo version upgrade
shaldengeki 66966fe
Fix a test's load ordering
shaldengeki d61aad1
Check in empty WORKSPACE files to make tests pass
shaldengeki b0039ee
_proto_py_pb2 -> _py_pb2
shaldengeki fa0d564
Merge branch 'main' into gazelle-plugin-generates-py-proto-library
dougthor42 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
gazelle/python/testdata/directive_python_generate_proto/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Directive: `python_generate_proto` | ||
|
||
This test case asserts that the `# gazelle:python_generate_proto` directive | ||
correctly: | ||
|
||
1. Uses the default value when `python_generate_proto` is not set. | ||
2. Generates (or not) `py_proto_library` when `python_generate_proto` is set, based on whether a proto is present. | ||
shaldengeki marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
[gh-2994]: https://github.com/bazel-contrib/rules_python/issues/2994 |
1 change: 1 addition & 0 deletions
1
gazelle/python/testdata/directive_python_generate_proto/WORKSPACE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# This is a Bazel workspace for the Gazelle test data. |
17 changes: 17 additions & 0 deletions
17
gazelle/python/testdata/directive_python_generate_proto/test.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Copyright 2023 The Bazel Authors. All rights reserved. | ||
shaldengeki marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
--- | ||
expect: | ||
exit_code: 0 |
10 changes: 10 additions & 0 deletions
10
gazelle/python/testdata/directive_python_generate_proto/test1_default_with_proto/BUILD.in
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
load("@rules_proto//proto:defs.bzl", "proto_library") | ||
|
||
# python_generate_proto is not set. | ||
# nevertheless, py_proto_library is generated. | ||
|
||
proto_library( | ||
name = "foo_proto", | ||
srcs = ["foo.proto"], | ||
visibility = ["//:__subpackages__"], | ||
) |
17 changes: 17 additions & 0 deletions
17
gazelle/python/testdata/directive_python_generate_proto/test1_default_with_proto/BUILD.out
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
load("@protobuf//bazel:py_proto_library.bzl", "py_proto_library") | ||
load("@rules_proto//proto:defs.bzl", "proto_library") | ||
|
||
# python_generate_proto is not set. | ||
# nevertheless, py_proto_library is generated. | ||
|
||
proto_library( | ||
name = "foo_proto", | ||
srcs = ["foo.proto"], | ||
visibility = ["//:__subpackages__"], | ||
) | ||
|
||
py_proto_library( | ||
name = "foo_proto_py_pb2", | ||
visibility = ["//:__subpackages__"], | ||
deps = [":foo_proto"], | ||
) |
7 changes: 7 additions & 0 deletions
7
gazelle/python/testdata/directive_python_generate_proto/test1_default_with_proto/foo.proto
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
syntax = "proto3"; | ||
|
||
package foo; | ||
|
||
message Foo { | ||
string bar = 1; | ||
} | ||
shaldengeki marked this conversation as resolved.
Show resolved
Hide resolved
|
2 changes: 2 additions & 0 deletions
2
gazelle/python/testdata/directive_python_generate_proto/test2_default_without_proto/BUILD.in
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# python_generate_proto is not set. | ||
# Since no proto is present, no targets are generated. |
2 changes: 2 additions & 0 deletions
2
...lle/python/testdata/directive_python_generate_proto/test2_default_without_proto/BUILD.out
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# python_generate_proto is not set. | ||
# Since no proto is present, no targets are generated. |
9 changes: 9 additions & 0 deletions
9
gazelle/python/testdata/directive_python_generate_proto/test3_disabled_with_proto/BUILD.in
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
load("@rules_proto//proto:defs.bzl", "proto_library") | ||
|
||
# gazelle:python_generate_proto false | ||
|
||
proto_library( | ||
name = "foo_proto", | ||
srcs = ["foo.proto"], | ||
visibility = ["//:__subpackages__"], | ||
) |
9 changes: 9 additions & 0 deletions
9
gazelle/python/testdata/directive_python_generate_proto/test3_disabled_with_proto/BUILD.out
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
load("@rules_proto//proto:defs.bzl", "proto_library") | ||
|
||
# gazelle:python_generate_proto false | ||
|
||
proto_library( | ||
name = "foo_proto", | ||
srcs = ["foo.proto"], | ||
visibility = ["//:__subpackages__"], | ||
) |
7 changes: 7 additions & 0 deletions
7
gazelle/python/testdata/directive_python_generate_proto/test3_disabled_with_proto/foo.proto
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
syntax = "proto3"; | ||
|
||
package foo.bar; | ||
|
||
message Foo { | ||
string bar = 1; | ||
} |
1 change: 1 addition & 0 deletions
1
...lle/python/testdata/directive_python_generate_proto/test4_disabled_without_proto/BUILD.in
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# gazelle:python_generate_proto false |
1 change: 1 addition & 0 deletions
1
...le/python/testdata/directive_python_generate_proto/test4_disabled_without_proto/BUILD.out
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# gazelle:python_generate_proto false |
9 changes: 9 additions & 0 deletions
9
gazelle/python/testdata/directive_python_generate_proto/test5_enabled_with_proto/BUILD.in
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
load("@rules_proto//proto:defs.bzl", "proto_library") | ||
|
||
# gazelle:python_generate_proto true | ||
|
||
proto_library( | ||
name = "foo_proto", | ||
srcs = ["foo.proto"], | ||
visibility = ["//:__subpackages__"], | ||
) |
16 changes: 16 additions & 0 deletions
16
gazelle/python/testdata/directive_python_generate_proto/test5_enabled_with_proto/BUILD.out
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
load("@protobuf//bazel:py_proto_library.bzl", "py_proto_library") | ||
load("@rules_proto//proto:defs.bzl", "proto_library") | ||
|
||
# gazelle:python_generate_proto true | ||
|
||
proto_library( | ||
name = "foo_proto", | ||
srcs = ["foo.proto"], | ||
visibility = ["//:__subpackages__"], | ||
) | ||
|
||
py_proto_library( | ||
name = "foo_proto_py_pb2", | ||
visibility = ["//:__subpackages__"], | ||
deps = [":foo_proto"], | ||
) |
7 changes: 7 additions & 0 deletions
7
gazelle/python/testdata/directive_python_generate_proto/test5_enabled_with_proto/foo.proto
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
syntax = "proto3"; | ||
|
||
package foo; | ||
|
||
message Foo { | ||
string bar = 1; | ||
} |
1 change: 1 addition & 0 deletions
1
gazelle/python/testdata/directive_python_generate_proto/test6_enabled_without_proto/BUILD.in
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# gazelle:python_generate_proto true |
1 change: 1 addition & 0 deletions
1
...lle/python/testdata/directive_python_generate_proto/test6_enabled_without_proto/BUILD.out
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# gazelle:python_generate_proto true |
16 changes: 16 additions & 0 deletions
16
...e/python/testdata/directive_python_generate_proto/test7_removes_when_unnecessary/BUILD.in
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
load("@protobuf//bazel:py_proto_library.bzl", "py_proto_library") | ||
load("@rules_proto//proto:defs.bzl", "proto_library") | ||
|
||
# gazelle:python_generate_proto true | ||
|
||
proto_library( | ||
name = "foo_proto", | ||
srcs = ["foo.proto"], | ||
visibility = ["//:__subpackages__"], | ||
) | ||
|
||
py_proto_library( | ||
name = "foo_proto_py_pb2", | ||
visibility = ["//:__subpackages__"], | ||
deps = [":foo_proto"], | ||
) |
1 change: 1 addition & 0 deletions
1
.../python/testdata/directive_python_generate_proto/test7_removes_when_unnecessary/BUILD.out
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# gazelle:python_generate_proto true | ||
shaldengeki marked this conversation as resolved.
Show resolved
Hide resolved
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.