Skip to content

Commit 118aca0

Browse files
committed
Fixup documentation
1 parent 5e0b96d commit 118aca0

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ END_UNRELEASED_TEMPLATE
114114
* (gazelle) New directive `gazelle:python_generate_proto`; when `true`,
115115
Gazelle generates `py_proto_library` rules for `proto_library`. `false` by default.
116116
* (gazelle) New directive `gazelle:python_proto_naming_convention`; controls
117-
naming of `py_proto_library` rules. See `gazelle/README.md`.
117+
naming of `py_proto_library` rules.
118118

119119
{#v0-0-0-removed}
120120
### Removed

gazelle/README.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ Python-specific directives are as follows:
208208
| Controls the `py_binary` naming convention. Follows the same interpolation rules as `python_library_naming_convention`. | |
209209
| `# gazelle:python_test_naming_convention` | `$package_name$_test` |
210210
| Controls the `py_test` naming convention. Follows the same interpolation rules as `python_library_naming_convention`. | |
211-
| `# gazelle:python_proto_naming_convention` | `$proto_name$_py_pb2` |
212-
| Controls the `py_proto_library naming convention. It interpolates `$proto_name$` with the proto_library rule name, minus any trailing _proto. E.g. if the proto_library name is `foo_proto`, setting this to `$proto_name$_my_lib` would render to `foo_my_lib`. | |
211+
| [`# gazelle:python_proto_naming_convention`](#directive-python_proto_naming_convention) | `$proto_name$_py_pb2` |
212+
| Controls the `py_proto_library` naming convention. It interpolates `$proto_name$` with the proto_library rule name, minus any trailing _proto. E.g. if the proto_library name is `foo_proto`, setting this to `$proto_name$_my_lib` would render to `foo_my_lib`. | |
213213
| `# gazelle:resolve py ...` | n/a |
214214
| 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`. | |
215215
| [`# gazelle:python_default_visibility labels`](#directive-python_default_visibility) | |
@@ -264,6 +264,31 @@ py_libary(
264264

265265
[python-packaging-user-guide]: https://github.com/pypa/packaging.python.org/blob/4c86169a/source/tutorials/packaging-projects.rst
266266

267+
#### Directive: `python_proto_naming_convention`:
268+
269+
Set this directive to a string pattern to control how the generated `py_proto_library` targets are named. Gazelle will replace `$proto_name$` in the pattern with the name of the `proto_library` rule, stripping out a trailing `_proto`. For example:
270+
271+
```starlark
272+
# gazelle:python_generate_proto true
273+
# gazelle:python_proto_naming_convention my_custom_$proto_name$_pattern
274+
275+
proto_library(
276+
name = "foo_proto",
277+
srcs = ["foo.proto"],
278+
)
279+
```
280+
281+
produces the following `py_proto_library` rule:
282+
```starlark
283+
py_proto_library(
284+
name = "my_custom_foo_pattern",
285+
deps = [":foo_proto"],
286+
)
287+
```
288+
289+
The default naming convention is `$proto_name$_pb2_py`, so by default in the above example Gazelle would generate `foo_pb2_py`.
290+
291+
Note that the Python library will always be imported as `foo_pb2` in Python code, regardless of the naming convention. Also note that Gazelle is currently not able to map said imports, e.g. `import foo_pb2`, to fill in `py_proto_library` targets as dependencies of other rules.
267292

268293
#### Directive: `python_default_visibility`:
269294

gazelle/python/testdata/directive_python_proto_naming_convention/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,4 @@ correctly:
55

66
1. Has no effect on pre-existing `py_proto_library` when `gazelle:python_generate_proto` is disabled.
77
2. Uses the default value when proto generation is on and `python_proto_naming_convention` is not set.
8-
2. Uses the provided naming convention when proto generation is on and `python_proto_naming_convention` is set.
9-
10-
[gh-3081]: https://github.com/bazel-contrib/rules_python/issues/3081
8+
3. Uses the provided naming convention when proto generation is on and `python_proto_naming_convention` is set.

0 commit comments

Comments
 (0)