Skip to content

Commit

Permalink
fix(gazelle): Consistent substitution pattern for python_default_visi…
Browse files Browse the repository at this point in the history
…bility directive (bazelbuild#1835)

Make the substitution pattern for `python_default_visibility` consistent
with the existing `python_*_naming_convention` pattern.

In bazelbuild#1787 I added the `python_default_visibility` directive and used a
substitution pattern `$python_root`. However, I missed that the existing
`python_*_naming_convention` directives include a trailing `$`.

This PR is just:
```
rg -l -F "\$python_root" | xargs sed -i 's/\$python_root/$python_root$/g'
```
  • Loading branch information
dougthor42 authored Apr 7, 2024
1 parent cdc7f2f commit 24a910d
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions gazelle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ Python-specific directives are as follows:
| `# 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_default_visibility labels`](#directive-python_default_visibility) | |
| Instructs gazelle to use these visibility labels on all python targets. `labels` is a comma-separated list of labels (without spaces). | `//$python_root:__subpackages__` |
| Instructs gazelle to use these visibility labels on all python targets. `labels` is a comma-separated list of labels (without spaces). | `//$python_root$:__subpackages__` |
| [`# gazelle:python_visibility label`](#directive-python_visibility) | |
| Appends additional visibility labels to each generated target. This directive can be set multiple times. | |
| [`# gazelle:python_test_file_pattern`](#directive-python_test_file_pattern) | `*_test.py,test_*.py` |
Expand Down Expand Up @@ -268,11 +268,11 @@ py_library(
```

You can also inject the `python_root` value by using the exact string
`$python_root`. All instances of this string will be replaced by the `python_root`
`$python_root$`. All instances of this string will be replaced by the `python_root`
value.

```starlark
# gazelle:python_default_visibility //$python_root:__pkg__,//foo/$python_root/tests:__subpackages__
# gazelle:python_default_visibility //$python_root$:__pkg__,//foo/$python_root$/tests:__subpackages__

# Assuming the "# gazelle:python_root" directive is set in ./py/src/BUILD.bazel,
# the results will be:
Expand Down
4 changes: 2 additions & 2 deletions gazelle/python/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ func (py *Configurer) Configure(c *config.Config, rel string, f *rule.File) {
config.SetDefaultVisibility([]string{defaultVisibility})
default:
// Handle injecting the python root. Assume that the user used the
// exact string "$python_root".
labels := strings.ReplaceAll(directiveArg, "$python_root", config.PythonProjectRoot())
// exact string "$python_root$".
labels := strings.ReplaceAll(directiveArg, "$python_root$", config.PythonProjectRoot())
config.SetDefaultVisibility(strings.Split(labels, ","))
}
case pythonconfig.Visibility:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# gazelle:python_root
# gazelle:python_default_visibility //foo/$python_root/bar:__pkg__
# gazelle:python_default_visibility //foo/$python_root$/bar:__pkg__
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
load("@rules_python//python:defs.bzl", "py_library")

# gazelle:python_root
# gazelle:python_default_visibility //foo/$python_root/bar:__pkg__
# gazelle:python_default_visibility //foo/$python_root$/bar:__pkg__

py_library(
name = "test3_injection",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# proj1 depends on proj2
# So we have to make sure that proj2 is visible by proj1
# gazelle:python_default_visibility //$python_root:__subpackages__,//test8_multiple_python_root_dirs/proj1/src:__subpackages__
# gazelle:python_default_visibility //$python_root$:__subpackages__,//test8_multiple_python_root_dirs/proj1/src:__subpackages__
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ load("@rules_python//python:defs.bzl", "py_library")

# proj1 depends on proj2
# So we have to make sure that proj2 is visible by proj1
# gazelle:python_default_visibility //$python_root:__subpackages__,//test8_multiple_python_root_dirs/proj1/src:__subpackages__
# gazelle:python_default_visibility //$python_root$:__subpackages__,//test8_multiple_python_root_dirs/proj1/src:__subpackages__

py_library(
name = "pkg2",
Expand Down

0 comments on commit 24a910d

Please sign in to comment.