You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs(gazelle): Add details about python_root directive. (#1782)
While figuring out how to use gazelle with a `src` dir (see
#1775) (I figured it
out by the way, hence this PR), I noticed that the docs were a little
unclear.
This PR updates the `gazelle` docs to include details about the
`python_root` directive and how to use it.
I also fix a the default value for the
`python_generation_mode_per_file_include_init` directive, as it was
incorrectly listed as "package".
| Controls whether the Python extension is enabled or not. Sub-packages inherit this value. Can be either "enabled" or "disabled". ||
179
-
|`# gazelle:python_root`| n/a |
180
-
| Sets a Bazel package as a Python root. This is used on monorepos with multiple Python projects that don't share the top-level of the workspace as the root. ||
| Sets a Bazel package as a Python root. This is used on monorepos with multiple Python projects that don't share the top-level of the workspace as the root. See [Directive: `python_root`](#directive-python_root) below. ||
| Controls whether `__init__.py` files are included as srcs in each generated target when target generation mode is "file". Can be "true", or "false" ||
| Controls the `py_library` naming convention. It interpolates `$package_name$` with the Bazel package name. E.g. if the Bazel package name is `foo`, setting this to `$package_name$_my_lib` would result in a generated target named `foo_my_lib`. ||
@@ -199,6 +199,43 @@ Python-specific directives are as follows:
199
199
|`# gazelle:resolve py ...`| n/a |
200
200
| 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`. ||
201
201
202
+
203
+
#### Directive: `python_root`:
204
+
205
+
Set this directive within the Bazel package that you want to use as the Python root.
206
+
For example, if using a `src` dir (as recommended by the [Python Packaging User
207
+
Guide][python-packaging-user-guide]), then set this directive in `src/BUILD.bazel`:
208
+
209
+
```starlark
210
+
# ./src/BUILD.bazel
211
+
# Tell gazelle that are python root is the same dir as this Bazel package.
212
+
# gazelle:python_root
213
+
```
214
+
215
+
Note that the directive does not have any arguments.
216
+
217
+
Gazelle will then add the necessary `imports` attribute to all targets that it
0 commit comments