-
Notifications
You must be signed in to change notification settings - Fork 541
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
feat(gazelle): Add "python_visibility" directive that appends additional visibility labels #1784
Merged
f0rmiga
merged 10 commits into
bazelbuild:main
from
dougthor42:gazelle-python-visibility
Mar 1, 2024
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7ee8023
Add test case
dougthor42 8c4680d
Add python_visibility directive
dougthor42 4fe0e69
Update README
dougthor42 6127e39
spelling
dougthor42 e084263
Merge branch 'main' into gazelle-python-visibility
dougthor42 afcec2b
Move things around in README.md
dougthor42 e3ec878
s/append/appends/g in readme per code review.
dougthor42 ccb9b49
s/Extra//g per code review
dougthor42 dbe4724
Remove TODO
dougthor42 c48a65b
_actually_ remove all the 'extra' prefixes.
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 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 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 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 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 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,4 @@ | ||
# Directives can be added in any order. They will be ordered alphabetically | ||
# when added. | ||
# gazelle:python_visibility //tests:__pkg__ | ||
# gazelle:python_visibility //bar:baz |
16 changes: 16 additions & 0 deletions
16
gazelle/python/testdata/directive_python_visibility/BUILD.out
This file contains 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("@rules_python//python:defs.bzl", "py_library") | ||
|
||
# Directives can be added in any order. They will be ordered alphabetically | ||
# when added. | ||
# gazelle:python_visibility //tests:__pkg__ | ||
# gazelle:python_visibility //bar:baz | ||
|
||
py_library( | ||
name = "directive_python_visibility", | ||
srcs = ["foo.py"], | ||
visibility = [ | ||
"//:__subpackages__", | ||
"//bar:baz", | ||
"//tests:__pkg__", | ||
], | ||
) |
4 changes: 4 additions & 0 deletions
4
gazelle/python/testdata/directive_python_visibility/README.md
This file contains 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,4 @@ | ||
# Directive: `python_visibility` | ||
|
||
This test case asserts that the `# gazelle:python_visibility` directive correctly | ||
appends multiple labels to the target's `visibility` parameter. |
This file contains 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. |
This file contains 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 @@ | ||
def func(): | ||
print("library_func") |
4 changes: 4 additions & 0 deletions
4
gazelle/python/testdata/directive_python_visibility/subdir/BUILD.in
This file contains 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,4 @@ | ||
# python_visibilty directive applies to all child bazel packages. | ||
# Thus, the generated file for this package will also have vis for | ||
# //tests:__pkg__ and //bar:baz in addition to the default. | ||
# gazelle:python_visibility //tests:__subpackages__ |
20 changes: 20 additions & 0 deletions
20
gazelle/python/testdata/directive_python_visibility/subdir/BUILD.out
This file contains 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,20 @@ | ||
load("@rules_python//python:defs.bzl", "py_library") | ||
|
||
# python_visibilty directive applies to all child bazel packages. | ||
# Thus, the generated file for this package will also have vis for | ||
# //tests:__pkg__ and //bar:baz in addition to the default. | ||
# gazelle:python_visibility //tests:__subpackages__ | ||
|
||
py_library( | ||
name = "subdir", | ||
srcs = [ | ||
"__init__.py", | ||
"bar.py", | ||
], | ||
visibility = [ | ||
"//:__subpackages__", | ||
"//bar:baz", | ||
"//tests:__pkg__", | ||
"//tests:__subpackages__", | ||
], | ||
) |
Empty file.
Empty file.
17 changes: 17 additions & 0 deletions
17
gazelle/python/testdata/directive_python_visibility/test.yaml
This file contains 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. | ||
# | ||
# 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 |
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that I'd be able to do
instead, but I would get this error:
I'm relatively new to go and haven't use the
gods.TreeSet
package before, so I'm not sure why things don't work.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can follow the pattern from above. See
addModuleDependencies
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... looks like doing so would mean having to adjust the arg type from
[]string
to*treeset.Set
, which would cascade togenerate.go
.As-is, the diff is smaller and I'm always a fan of using built-in types when possible.
That said, LMK if you feel strongly that this func should be
*treeset.Set
and I'll be happy to change it.