Skip to content

Commit 39703fa

Browse files
authored
docs(gazelle): Start migrating Gazelle docs to ReadTheDocs, part 1 of ~5 (bazel-contrib#3129)
Part of bazel-contrib#3082 First of probably 5 PRs. + Set up the Bazel config so that the rules_python root docs can reference and use the gazelle/docs directory. + Replace the original `docs/gazelle.md` with `gazelle/docs/index.md` + Migrate general info from `gazelle/README.md` to `gazelle/docs/index.md` + Mechanical updates: + Wrap at ~80 chars + Use MyST directives and roles. + Also a drive-by update to building and running docs _without_ `ibazel`.
1 parent 6819b84 commit 39703fa

File tree

7 files changed

+70
-36
lines changed

7 files changed

+70
-36
lines changed

docs/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ sphinx_docs(
5555
"_*",
5656
"*.inv*",
5757
],
58-
),
58+
) + ["//gazelle/docs"],
5959
config = "conf.py",
6060
formats = [
6161
"html",

docs/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@ changes and re-run the build process, and you can simply refresh your browser to
2828
see the changes. Using ibazel is not required; you can manually run the
2929
equivalent bazel command if desired.
3030

31+
An alternative to `ibazel` is using `inotify` on Linux systems:
32+
33+
```
34+
inotifywait --event modify --monitor . --recursive --includei '^.*\.md$' |
35+
while read -r dir events filename; do bazel build //docs:docs; done;
36+
```
37+
38+
And lastly, a poor-man's `ibazel` and `inotify` is simply `watch` with
39+
a reasonable interval like 10s:
40+
41+
```
42+
watch --interval 10 bazel build //docs:docs
43+
```
44+
3145
### Installing ibazel
3246

3347
The `ibazel` tool can be used to automatically rebuild the docs as you

docs/gazelle.md

Lines changed: 0 additions & 9 deletions
This file was deleted.

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ pypi/index
9999
Toolchains <toolchains>
100100
coverage
101101
precompiling
102-
gazelle
102+
gazelle/docs/index
103103
REPL <repl>
104104
Extending <extending>
105105
Contributing <contributing>

gazelle/README.md

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
# Python Gazelle plugin
22

3-
[Gazelle](https://github.com/bazelbuild/bazel-gazelle)
4-
is a build file generator for Bazel projects. It can create new BUILD.bazel files for a project that follows language conventions, and it can update existing build files to include new sources, dependencies, and options.
3+
:::{note}
4+
The gazelle plugin docs are being migrated to our primary documentation on
5+
ReadTheDocs. Please see https://rules-python.readthedocs.io/gazelle/docs/index.html.
6+
:::
57

6-
Gazelle may be run by Bazel using the gazelle rule, or it may be installed and run as a command line tool.
7-
8-
This directory contains a plugin for
9-
[Gazelle](https://github.com/bazelbuild/bazel-gazelle)
10-
that generates BUILD files content for Python code. When Gazelle is run as a command line tool with this plugin, it embeds a Python interpreter resolved during the plugin build.
11-
The behavior of the plugin is slightly different with different version of the interpreter as the Python `stdlib` changes with every minor version release.
12-
Distributors of Gazelle binaries should, therefore, build a Gazelle binary for each OS+CPU architecture+Minor Python version combination they are targeting.
13-
14-
The following instructions are for when you use [bzlmod](https://docs.bazel.build/versions/5.0.0/bzlmod.html).
15-
Please refer to older documentation that includes instructions on how to use Gazelle
16-
without using bzlmod as your dependency manager.
178

189
## Example
1910

@@ -153,18 +144,6 @@ gazelle(
153144
That's it, now you can finally run `bazel run //:gazelle` anytime
154145
you edit Python code, and it should update your `BUILD` files correctly.
155146

156-
## Usage
157-
158-
Gazelle is non-destructive.
159-
It will try to leave your edits to BUILD files alone, only making updates to `py_*` targets.
160-
However it will remove dependencies that appear to be unused, so it's a
161-
good idea to check in your work before running Gazelle so you can easily
162-
revert any changes it made.
163-
164-
The rules_python extension assumes some conventions about your Python code.
165-
These are noted below, and might require changes to your existing code.
166-
167-
Note that the `gazelle` program has multiple commands. At present, only the `update` command (the default) does anything for Python code.
168147

169148
### Directives
170149

gazelle/docs/BUILD.bazel

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
filegroup(
2+
name = "docs",
3+
srcs = glob(["*.md"]),
4+
visibility = ["//visibility:public"],
5+
)

gazelle/docs/index.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Gazelle Plugin
2+
3+
[Gazelle][gazelle] is a build file generator for Bazel projects. It can
4+
create new `BUILD` or `BUILD.bazel` files for a project that
5+
follows language conventions and update existing build files to include new
6+
sources, dependencies, and options.
7+
8+
[gazelle]: https://github.com/bazel-contrib/bazel-gazelle
9+
10+
Bazel may run Gazelle using the Gazelle rule, or Gazelle may be installed and run
11+
as a command line tool.
12+
13+
The {gh-path}`gazelle` directory contains a plugin for Gazelle
14+
that generates `BUILD` files content for Python code. When Gazelle is
15+
run as a command line tool with this plugin, it embeds a Python interpreter
16+
resolved during the plugin build. The behavior of the plugin is slightly
17+
different with different version of the interpreter as the Python
18+
`stdlib` changes with every minor version release. Distributors of Gazelle
19+
binaries should, therefore, build a Gazelle binary for each OS+CPU
20+
architecture+Minor Python version combination they are targeting.
21+
22+
:::{note}
23+
These instructions are for when you use [bzlmod][bzlmod]. Please refer to
24+
older documentation that includes instructions on how to use Gazelle
25+
without using bzlmod as your dependency manager.
26+
:::
27+
28+
[bzlmod]: https://bazel.build/external/module
29+
30+
Gazelle is non-destructive. It will try to leave your edits to `BUILD`
31+
files alone, only making updates to `py_*` targets. However it **will
32+
remove** dependencies that appear to be unused, so it's a good idea to check
33+
in your work before running Gazelle so you can easily revert any changes it made.
34+
35+
The `rules_python` extension assumes some conventions about your Python code.
36+
These are noted in the subsequent documents, and might require changes to your
37+
existing code.
38+
39+
Note that the `gazelle` program has multiple commands. At present, only
40+
the `update` command (the default) does anything for Python code.
41+
42+
43+
```{toctree}
44+
:maxdepth: 1
45+
```

0 commit comments

Comments
 (0)