Skip to content

Commit 24a910d

Browse files
authored
fix(gazelle): Consistent substitution pattern for python_default_visibility directive (bazel-contrib#1835)
Make the substitution pattern for `python_default_visibility` consistent with the existing `python_*_naming_convention` pattern. In bazel-contrib#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' ```
1 parent cdc7f2f commit 24a910d

File tree

6 files changed

+9
-9
lines changed

6 files changed

+9
-9
lines changed

gazelle/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ Python-specific directives are as follows:
199199
| `# gazelle:resolve py ...` | n/a |
200200
| 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`. | |
201201
| [`# gazelle:python_default_visibility labels`](#directive-python_default_visibility) | |
202-
| Instructs gazelle to use these visibility labels on all python targets. `labels` is a comma-separated list of labels (without spaces). | `//$python_root:__subpackages__` |
202+
| Instructs gazelle to use these visibility labels on all python targets. `labels` is a comma-separated list of labels (without spaces). | `//$python_root$:__subpackages__` |
203203
| [`# gazelle:python_visibility label`](#directive-python_visibility) | |
204204
| Appends additional visibility labels to each generated target. This directive can be set multiple times. | |
205205
| [`# gazelle:python_test_file_pattern`](#directive-python_test_file_pattern) | `*_test.py,test_*.py` |
@@ -268,11 +268,11 @@ py_library(
268268
```
269269

270270
You can also inject the `python_root` value by using the exact string
271-
`$python_root`. All instances of this string will be replaced by the `python_root`
271+
`$python_root$`. All instances of this string will be replaced by the `python_root`
272272
value.
273273

274274
```starlark
275-
# gazelle:python_default_visibility //$python_root:__pkg__,//foo/$python_root/tests:__subpackages__
275+
# gazelle:python_default_visibility //$python_root$:__pkg__,//foo/$python_root$/tests:__subpackages__
276276

277277
# Assuming the "# gazelle:python_root" directive is set in ./py/src/BUILD.bazel,
278278
# the results will be:

gazelle/python/configure.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ func (py *Configurer) Configure(c *config.Config, rel string, f *rule.File) {
177177
config.SetDefaultVisibility([]string{defaultVisibility})
178178
default:
179179
// Handle injecting the python root. Assume that the user used the
180-
// exact string "$python_root".
181-
labels := strings.ReplaceAll(directiveArg, "$python_root", config.PythonProjectRoot())
180+
// exact string "$python_root$".
181+
labels := strings.ReplaceAll(directiveArg, "$python_root$", config.PythonProjectRoot())
182182
config.SetDefaultVisibility(strings.Split(labels, ","))
183183
}
184184
case pythonconfig.Visibility:
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# gazelle:python_root
2-
# gazelle:python_default_visibility //foo/$python_root/bar:__pkg__
2+
# gazelle:python_default_visibility //foo/$python_root$/bar:__pkg__

gazelle/python/testdata/directive_python_default_visibility/test3_injection/BUILD.out

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
load("@rules_python//python:defs.bzl", "py_library")
22

33
# gazelle:python_root
4-
# gazelle:python_default_visibility //foo/$python_root/bar:__pkg__
4+
# gazelle:python_default_visibility //foo/$python_root$/bar:__pkg__
55

66
py_library(
77
name = "test3_injection",
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# proj1 depends on proj2
22
# So we have to make sure that proj2 is visible by proj1
3-
# gazelle:python_default_visibility //$python_root:__subpackages__,//test8_multiple_python_root_dirs/proj1/src:__subpackages__
3+
# gazelle:python_default_visibility //$python_root$:__subpackages__,//test8_multiple_python_root_dirs/proj1/src:__subpackages__

gazelle/python/testdata/directive_python_default_visibility/test8_multiple_python_root_dirs/proj2/src/pkg2/BUILD.out

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ load("@rules_python//python:defs.bzl", "py_library")
22

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

77
py_library(
88
name = "pkg2",

0 commit comments

Comments
 (0)