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.
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.
You can follow the pattern from above. See addModuleDependencies.
There was a problem hiding this comment.
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/README.md
Outdated
| | `# 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.
| | 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. | | |
gazelle/README.md
Outdated
|
|
||
| #### Directive: `python_visibility`: | ||
|
|
||
| Append additional `visibility` labels to each generated target. |
There was a problem hiding this comment.
| Append additional `visibility` labels to each generated target. | |
| Appends additional `visibility` labels to each generated target. |
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.
To follow the pattern:
| ExtraVisibility = "python_visibility" | |
| Visibility = "python_visibility" |
There was a problem hiding this comment.
SGTM, updated..
| for _, item := range visibility { | ||
| t.visibility.Add(item) | ||
| } |
There was a problem hiding this comment.
You can follow the pattern from above. See addModuleDependencies.
dougthor42
left a comment
There was a problem hiding this comment.
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
| | `# 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. | | |
gazelle/README.md
Outdated
|
|
||
| #### Directive: `python_visibility`: | ||
|
|
||
| Append additional `visibility` labels to each generated target. |
| for _, item := range visibility { | ||
| t.visibility.Add(item) | ||
| } |
There was a problem hiding this comment.
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.
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. |
f0rmiga
left a comment
There was a problem hiding this comment.
Looks good, just address my last comments and ping me to merge. Thanks!
gazelle/python/generate.go
Outdated
|
|
||
| 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.
Please, remove this TODO item since there's an issue already.
gazelle/pythonconfig/pythonconfig.go
Outdated
| libraryNamingConvention string | ||
| binaryNamingConvention string | ||
| testNamingConvention string | ||
| extraVisibility []string |
There was a problem hiding this comment.
I hoped you'd remove the extra everywhere.
There was a problem hiding this comment.
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
visibilityattribute of generated targets.This directive acts similar to1 the
go_visibilitydirective.
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
./examplesdirectory (issue#1775).
Footnotes
At least, similar based on docs. I haven't done any actual
comparison. ↩