-
Notifications
You must be signed in to change notification settings - Fork 543
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
feat(gazelle): Add "python_visibility" directive that appends additional visibility labels #1784
Conversation
for _, item := range visibility { | ||
t.visibility.Add(item) | ||
} |
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
t.visibility.Add(visibility...)
instead, but I would get this error:
python/target.go:104:19: cannot use visibility (variable of type []string) as type []interface{} in argument to t.visibility.Add
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 to generate.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.
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.
Thanks for adding tests.
gazelle/README.md
Outdated
@@ -198,6 +198,54 @@ Python-specific directives are as follows: | |||
| Controls the `py_test` naming convention. Follows the same interpolation rules as `python_library_naming_convention`. | | | |||
| `# gazelle:resolve py ...` | n/a | | |||
| Instructs the plugin what target to add as a dependency to satisfy a given import statement. The syntax is `# gazelle:resolve py import-string label` where `import-string` is the symbol in the python `import` statement, and `label` is the Bazel label that Gazelle should write in `deps`. | | | |||
| [`# gazelle:python_visibility label`](#directive-python_visibility) | | | |||
| Append additional visibility labels to each generated target. This directive can be set multiple times. | | |
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.
| Append additional visibility labels to each generated target. This directive can be set multiple times. | | | |
| Appends additional visibility labels to each generated target. This directive can be set multiple times. | | |
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.
👍
gazelle/README.md
Outdated
|
||
#### Directive: `python_visibility`: | ||
|
||
Append additional `visibility` labels to each generated target. |
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.
Append additional `visibility` labels to each generated target. | |
Appends additional `visibility` labels to each generated target. |
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.
Done
gazelle/pythonconfig/pythonconfig.go
Outdated
// ExtraVisibility represents the directive that controls what additional | ||
// visibility labels are added to generated targets. It mimics the behavior | ||
// of the `go_visibility` directive. | ||
ExtraVisibility = "python_visibility" |
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.
To follow the pattern:
ExtraVisibility = "python_visibility" | |
Visibility = "python_visibility" |
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.
SGTM, updated..
for _, item := range visibility { | ||
t.visibility.Add(item) | ||
} |
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.
Thanks for adding tests.
Of course! I wouldn't have it any other way.
Addressed review comments, only one open question if you want me to change to addVisibility(visibility *treeset.Set)
gazelle/README.md
Outdated
@@ -198,6 +198,54 @@ Python-specific directives are as follows: | |||
| Controls the `py_test` naming convention. Follows the same interpolation rules as `python_library_naming_convention`. | | | |||
| `# gazelle:resolve py ...` | n/a | | |||
| Instructs the plugin what target to add as a dependency to satisfy a given import statement. The syntax is `# gazelle:resolve py import-string label` where `import-string` is the symbol in the python `import` statement, and `label` is the Bazel label that Gazelle should write in `deps`. | | | |||
| [`# gazelle:python_visibility label`](#directive-python_visibility) | | | |||
| Append additional visibility labels to each generated target. This directive can be set multiple times. | | |
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.
👍
gazelle/README.md
Outdated
|
||
#### Directive: `python_visibility`: | ||
|
||
Append additional `visibility` labels to each generated target. |
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.
Done
for _, item := range visibility { | ||
t.visibility.Add(item) | ||
} |
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 to generate.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.
gazelle/pythonconfig/pythonconfig.go
Outdated
// ExtraVisibility represents the directive that controls what additional | ||
// visibility labels are added to generated targets. It mimics the behavior | ||
// of the `go_visibility` directive. | ||
ExtraVisibility = "python_visibility" |
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.
SGTM, updated..
Note, that the PR will get squashed and the commit message on the main branch will be the description of the PR. So consider improving the wording/layout there. That said, I like PRs being submitted as a way to spark the discussion, it's not rude at all. It's sometimes really nice to discuss something concrete. So thank you for doing just that! |
PR message updated - removed the note and kept lines down to ~72 chars.
You're welcome! Some people like it, others hate it haha. Personally I also find it nice to discuss something concrete. |
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.
Looks good, just address my last comments and ping me to merge. Thanks!
gazelle/python/generate.go
Outdated
@@ -212,7 +212,10 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes | |||
} | |||
|
|||
parser := newPython3Parser(args.Config.RepoRoot, args.Rel, cfg.IgnoresDependency) | |||
visibility := fmt.Sprintf("//%s:__subpackages__", pythonProjectRoot) | |||
// TODO(gh-1682): Add support for default_visibility directive and replace |
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.
Please, remove this TODO item since there's an issue already.
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.
Done!
gazelle/pythonconfig/pythonconfig.go
Outdated
@@ -136,6 +140,7 @@ type Config struct { | |||
libraryNamingConvention string | |||
binaryNamingConvention string | |||
testNamingConvention string | |||
extraVisibility []string |
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 hoped you'd remove the extra
everywhere.
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 could have sworn I did... Sorry about that, I definitely meant to.
...
...
Ah, looks like I stashed the changes instead of committing them. /facepalm. Anyway, updated 👍.
I see that the
I am not sure if I worded it well enough, so feel free to improve upon in! |
Ah sorry. I'll do that tonight. I thought it was automatic as part of the
Conventional Commits.
…On Tue, Mar 12, 2024, 18:04 Ignas Anikevicius ***@***.***> wrote:
I see that the CHANGELOG.md did not get updated when merging this PR.
Would one of you be willing to create a followup PR to add the a short
snippet about the new features? Something like:
Added:
* (gazelle) Added a new `python_visibility` directive to control visibility of
generated targets to allow sharing of targets between trees with different
`python_root` values.
I am not sure if I worded it well enough, so feel free to improve upon in!
—
Reply to this email directly, view it on GitHub
<#1784 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABJDFEJYNHQOWDXISSUZEWLYX6QZVAVCNFSM6AAAAABD42DP26VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOJSHEYDSMJXGE>
.
You are receiving this because you modified the open/close state.Message
ID: ***@***.***>
|
Fixes #1783.
Add a new gazelle directive,
python_visibility
, that allowsusers to add labels to the
visibility
attribute of generated targets.This directive acts similar to1 the
go_visibility
directive.
The primary use case is for python projects that separate unit test
files from the python packages/modules that they test, like so:
A future PR will add an example to the
./examples
directory (issue#1775).
Footnotes
At least, similar based on docs. I haven't done any actual
comparison. ↩