Skip to content

Commit fb114ab

Browse files
alexeaglemattem
andauthored
chore(docs): improved navigation and structure for API docs (#400)
Follows pattern from our other rulesets, makes it easier to link users to docs. --- ### Changes are visible to end-users: no ### Test plan None --------- Co-authored-by: Matt Mackay <[email protected]>
1 parent c355f6b commit fb114ab

File tree

17 files changed

+633
-333
lines changed

17 files changed

+633
-333
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
docs/*.md linguist-generated=true
2+
docs/migrating.md linguist-generated=false
23

34
# Configuration for 'git archive'
45
# see https://git-scm.com/docs/git-archive/2.40.0#ATTRIBUTES

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ artifact or a version fetched from the internet, run this from this
3030
directory:
3131

3232
```sh
33-
OVERRIDE="--override_repository=rules_py=$(pwd)/rules_py"
33+
OVERRIDE="--override_repository=aspect_rules_py=$(pwd)/rules_py"
3434
echo "common $OVERRIDE" >> ~/.bazelrc
3535
```
3636

37-
This means that any usage of `@rules_py` on your system will point to this folder.
37+
This means that any usage of `@aspect_rules_py` on your system will point to this folder.
3838

3939
## Releasing
4040

README.md

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,25 @@ The lower layer of `rules_python` is currently reused, dealing with the toolchai
77
However, this ruleset introduces a new implementation of `py_library`, `py_binary`, and `py_test`.
88
Our philosophy is to behave more like idiomatic python ecosystem tools, where rules_python is closely
99
tied to the way Google does Python development in their internal monorepo, google3.
10+
However we try to maintain compatibility with rules_python's rules for most use cases.
1011

11-
| Layer | Legacy | Recommended |
12-
| ------------------------------------------- | ------------ | ---------------- |
13-
| rules: BUILD file UI | rules_python | **rules_py** |
14-
| gazelle: generate BUILD files | rules_python | rules_python [1] |
15-
| pip_parse: fetch and install deps from pypi | rules_python | rules_python |
16-
| toolchain: fetch hermetic interpreter | rules_python | rules_python |
12+
| Layer | Legacy | Recommended |
13+
| ------------------------------------------- | ------------ | -------------------- |
14+
| toolchain: fetch hermetic interpreter | rules_python | rules_python |
15+
| pip.parse: fetch and install deps from pypi | rules_python | rules_python |
16+
| gazelle: generate BUILD files | rules_python | [`aspect configure`] |
17+
| rules: user-facing implementations | rules_python | **rules_py** |
18+
19+
Watch our video series for a quick tutorial on how rules_py makes it easy to do Python with Bazel:
20+
[![youtube playlist](https://i.ytimg.com/vi/Ms9qX0Yyn0s/hqdefault.jpg)](https://www.youtube.com/playlist?list=PLLU28e_DRwdu46fldnYzyFYvSJLjVFICd)
1721

1822
_Need help?_ This ruleset has support provided by https://aspect.dev.
1923

20-
[1] we will likely fork the extension for performance, using TreeSitter to parse Python code rather than a Python program.
24+
[`aspect configure`]: https://docs.aspect.build/cli/commands/aspect_configure
2125

2226
## Differences
2327

24-
We think you'll love rules_py because:
28+
We think you'll love rules_py because it fixes many issues with rules_python's rule implementations:
2529

2630
- The launcher uses the Bash toolchain rather than Python, so we have no dependency on a system interpreter. Fixes:
2731
- [py_binary with hermetic toolchain requires a system interpreter](https://github.com/bazelbuild/rules_python/issues/691)
@@ -32,8 +36,8 @@ We think you'll love rules_py because:
3236
- [sys.path[0] breaks out of runfile tree.](https://github.com/bazelbuild/rules_python/issues/382)
3337
- [User site-packages directory should be ignored](https://github.com/bazelbuild/rules_python/issues/1059)
3438
- We create a python-idiomatic virtualenv to run actions, which means better compatibility with userland implementations of [importlib](https://docs.python.org/3/library/importlib.html).
35-
- Thanks to the virtualenv, you can open the project in an editor like PyCharm and have working auto-complete, jump-to-definition, etc. Fixes:
36-
- [Smooth IDE support for python_rules](https://github.com/bazelbuild/rules_python/issues/1401)
39+
- Thanks to the virtualenv, you can open the project in an editor like PyCharm or VSCode and have working auto-complete, jump-to-definition, etc.
40+
- Fixes [Smooth IDE support for python_rules](https://github.com/bazelbuild/rules_python/issues/1401)
3741

3842
> [!NOTE]
3943
> What about the "starlarkification" effort in rules_python?
@@ -50,12 +54,28 @@ Follow instructions from the release you wish to use:
5054

5155
### Using with Gazelle
5256

53-
In any ancestor `BUILD` file of the Python code, add these lines to instruct [Gazelle] to create rules_py variants of the `py_*` rules:
57+
In any ancestor `BUILD` file of the Python code, add these lines to instruct [Gazelle] to create `rules_py` variants of the `py_*` rules:
5458

5559
```
5660
# gazelle:map_kind py_library py_library @aspect_rules_py//py:defs.bzl
5761
# gazelle:map_kind py_binary py_binary @aspect_rules_py//py:defs.bzl
5862
# gazelle:map_kind py_test py_test @aspect_rules_py//py:defs.bzl
5963
```
6064

61-
[Gazelle]: https://github.com/bazelbuild/rules_python/blob/main/gazelle/README.md
65+
[gazelle]: https://github.com/bazelbuild/rules_python/blob/main/gazelle/README.md
66+
67+
# Public API
68+
69+
## Executables
70+
71+
- [py_binary](docs/py_binary.md) an executable Python program, used with `bazel run` or as a tool.
72+
- [py_test](docs/py_test.md) a Python program that executes a test runner such as `unittest` or `pytest`, to be used with `bazel test`.
73+
- [py_venv](docs/venv.md) create a virtualenv for a `py_binary` or `py_test` target for use outside Bazel, such as in an editor/IDE.
74+
75+
## Packaging
76+
77+
- [py_pex_binary](docs/pex.md) Create a zip file containing a full Python application.
78+
79+
## Packages
80+
81+
- [py_library](docs/py_library.md) a unit of Python code, used as a dependency of other rules.

docs/BUILD.bazel

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,37 @@
33
load("@aspect_bazel_lib//lib:docs.bzl", "stardoc_with_diff_test", "update_docs")
44

55
stardoc_with_diff_test(
6-
name = "rules",
6+
name = "py_library",
7+
bzl_library_target = "//py/private:py_library",
8+
)
9+
10+
stardoc_with_diff_test(
11+
name = "py_binary",
12+
bzl_library_target = "//py:defs",
13+
symbol_names = [
14+
"py_binary",
15+
"py_binary_rule",
16+
],
17+
)
18+
19+
stardoc_with_diff_test(
20+
name = "py_test",
721
bzl_library_target = "//py:defs",
22+
symbol_names = [
23+
"py_test",
24+
"py_test_rule",
25+
"py_pytest_main",
26+
],
27+
)
28+
29+
stardoc_with_diff_test(
30+
name = "pex",
31+
bzl_library_target = "//py/private:py_pex_binary",
32+
)
33+
34+
stardoc_with_diff_test(
35+
name = "venv",
36+
bzl_library_target = "//py/private:py_venv",
837
)
938

1039
update_docs(name = "update")

docs/migrating.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Migrating rules from rules_python to rules_py
2+
3+
rules_py tries to closely mirror the API of rules_python.
4+
Migration is a "drop-in replacement" for the majority of use cases.
5+
6+
## Replace load statements
7+
8+
Instead of loading from `@rules_python//python:defs.bzl`, load from `@aspect_rules_py//py:defs.bzl`.
9+
The rest of the BUILD file can remain the same.
10+
11+
If using Gazelle, see the note on [using with Gazelle](/README.md#using-with-gazelle)
12+
13+
## Remaining notes
14+
15+
Users are encouraged to send a Pull Request to add more documentation as they uncover issues during migrations.

docs/pex.md

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/py_binary.md

Lines changed: 92 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)