Skip to content

Commit 5d7e620

Browse files
committed
Improve docs
1 parent c8d66a0 commit 5d7e620

File tree

3 files changed

+70
-61
lines changed

3 files changed

+70
-61
lines changed

BZLMOD_SUPPORT.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,10 @@ the toolchains rules_python registers**.
5151
NOTE: Regardless of your toolchain, due to
5252
[#691](https://github.com/bazelbuild/rules_python/issues/691), `rules_python`
5353
still relies on a local Python being available to bootstrap the program before
54-
handing over execution to the toolchain Python. To override this behaviour see
55-
{obj}`--bootstrap_impl=script`, which switches to `bash`-based bootstrap on
56-
UNIX systems.
54+
handing over execution to the toolchain Python.
55+
56+
To override this behaviour see {obj}`--bootstrap_impl=script`, which switches
57+
to `bash`-based bootstrap on UNIX systems.
5758

5859
### Better PyPI package downloading on bzlmod
5960

docs/getting-started.md

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Getting started
22

33
This doc is a simplified guide to help get started started quickly. It provides
4-
a simplified introduction to having a working Python program for both bzlmod
4+
a simplified introduction to having a working Python program for both `bzlmod`
55
and the older way of using `WORKSPACE`.
66

77
It assumes you have a `requirements.txt` file with your PyPI dependencies.
@@ -23,11 +23,11 @@ bazel_dep(name = "rules_python", version = "0.0.0")
2323

2424
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
2525
pip.parse(
26-
hub_name = "my_deps",
26+
hub_name = "pypi",
2727
python_version = "3.11",
2828
requirements_lock = "//:requirements.txt",
2929
)
30-
use_repo(pip, "my_deps")
30+
use_repo(pip, "pypi")
3131
```
3232

3333
## Using a WORKSPACE file
@@ -38,19 +38,14 @@ using Bzlmod. Here is a simplified setup to download the prebuilt runtimes.
3838
```starlark
3939
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
4040

41-
42-
# Update the SHA and VERSION to the lastest version available here:
43-
# https://github.com/bazelbuild/rules_python/releases.
44-
45-
SHA="84aec9e21cc56fbc7f1335035a71c850d1b9b5cc6ff497306f84cced9a769841"
46-
47-
VERSION="0.23.1"
41+
# Update the snippet based on the latest release below
42+
# https://github.com/bazelbuild/rules_python/releases
4843

4944
http_archive(
5045
name = "rules_python",
51-
sha256 = SHA,
52-
strip_prefix = "rules_python-{}".format(VERSION),
53-
url = "https://github.com/bazelbuild/rules_python/releases/download/{}/rules_python-{}.tar.gz".format(VERSION,VERSION),
46+
sha256 = "ca77768989a7f311186a29747e3e95c936a41dffac779aff6b443db22290d913",
47+
strip_prefix = "rules_python-0.36.0",
48+
url = "https://github.com/bazelbuild/rules_python/releases/download/0.36.0/rules_python-0.36.0.tar.gz",
5449
)
5550

5651
load("@rules_python//python:repositories.bzl", "py_repositories")
@@ -66,14 +61,12 @@ python_register_toolchains(
6661
python_version = "3.11",
6762
)
6863

69-
load("@python_3_11//:defs.bzl", "interpreter")
70-
7164
load("@rules_python//python:pip.bzl", "pip_parse")
7265

7366
pip_parse(
74-
...
75-
python_interpreter_target = interpreter,
76-
...
67+
name = "pypi",
68+
python_interpreter_target = "@python_3_11_host//:python",
69+
requirements_lock = "//:requirements.txt",
7770
)
7871
```
7972

@@ -89,8 +82,8 @@ py_binary(
8982
name = "main",
9083
srcs = ["main.py"],
9184
deps = [
92-
"@my_deps//foo",
93-
"@my_deps//bar",
85+
"@pypi//foo",
86+
"@pypi//bar",
9487
]
9588
)
9689
```

docs/index.md

Lines changed: 53 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,71 @@
11
# Python Rules for Bazel
22

3-
`rules_python` is the home for 4 major components:
4-
* the core Python rules -- `py_library`, `py_binary`, `py_test`,
5-
`py_proto_library`, and related symbols that provide the basis for Python
6-
support in Bazel.
3+
`rules_python` is the home for 4 major components with varying maturity levels.
74

8-
This is subject to our breaking change policy outlined in the <support>.
9-
* Package installation rules for integrating with PyPI and other SimpleAPI
10-
complying indexes.
5+
:::{topic} Core rules
116

12-
This is still `experimental` and the APIs might change more often than the
13-
core rules or you may experience regressions between the minor releases. In
14-
that case, please raise tickets to the GH issues bug tracker.
15-
* `sphinxdocs` rules allowing users to generate documentation from bazel or
16-
Python source code.
7+
The core Python rules -- `py_library`, `py_binary`, `py_test`,
8+
`py_proto_library`, and related symbols that provide the basis for Python
9+
support in Bazel.
1710

18-
This is available as is and without any guarantees. The semantic versioning
19-
used by `rules_python` does not apply to bazel rules or the output.
20-
* `gazelle` plugin for generating `BUILD.bazel` files based on Python source
21-
code.
11+
When using bazel 6, the core rules built into the Bazel binary, and the symbols
12+
in this repository are simple aliases. On bazel 7 and above `rules_python` uses
13+
a separate Starlark implementation,
14+
see {ref}`Migrating from the Bundled Rules` below.
2215

23-
This is available as is and without any guarantees. The semantic versioning
24-
used by `rules_python` does not apply to the plugin.
16+
Once rules_python 1.0 is released, they will follow
17+
[semantic versioning](https://semver.org) and the breaking change policy
18+
outlined in the [support](support) page.
2519

26-
Documentation for rules_python lives here and in the
27-
[Bazel Build Encyclopedia](https://docs.bazel.build/versions/master/be/python.html).
20+
:::
2821

29-
Examples are in the {gh-path}`examples` directory.
22+
:::{topic} PyPI integration
3023

31-
When using bazel 6, the core rules built into the Bazel binary, and the symbols
32-
in this repository are simple aliases. However, on bazel 7 and above starlark
33-
implementation in this repository is used.
34-
See {ref}`Migrating from the Bundled Rules` below.
24+
Package installation rules for integrating with PyPI and other SimpleAPI
25+
complying indexes.
26+
27+
These rules are still `experimental` and the APIs might change more often
28+
than the core rules or you may experience regressions between the minor
29+
releases. In that case, please raise tickets to the GH issues bug tracker.
30+
31+
:::
32+
33+
:::{topic} Sphinxdocs
34+
35+
`sphinxdocs` rules allowing users to generate documentation from bazel or
36+
Python source code.
37+
38+
This is available as is and the semantic versioning used by `rules_python` does
39+
not apply to bazel rules or the output.
40+
41+
:::
42+
43+
:::{topic} Gazelle plugin
3544

36-
The core rules are stable. Their implementation in Bazel is subject to Bazel's
37-
[backward compatibility policy](https://docs.bazel.build/versions/master/backward-compatibility.html).
38-
Once migrated to rules_python, they may evolve at a different
39-
rate, but this repository will still follow [semantic versioning](https://semver.org).
45+
`gazelle` plugin for generating `BUILD.bazel` files based on Python source
46+
code.
47+
48+
This is available as is and the semantic versioning used by `rules_python` does
49+
not apply to the plugin.
50+
51+
:::
4052

4153
The Bazel community maintains this repository. Neither Google nor the Bazel
4254
team provides support for the code. However, this repository is part of the
4355
test suite used to vet new Bazel releases. See {gh-path}`How to contribute
4456
<CONTRIBUTING.md>` for information on our development workflow.
4557

46-
## Bzlmod support
47-
48-
- Status: GA
58+
## Examples
4959

50-
See {gh-path}`Bzlmod support <BZLMOD_SUPPORT.md>` for any behaviour differences between
51-
`bzlmod` and `WORKSPACE`.
60+
This documentation is an example of `sphinxdocs` rules and the rest of the
61+
components have examples in the {gh-path}`examples` directory.
5262

5363
## Migrating from the bundled rules
5464

5565
The core rules are currently available in Bazel as built-in symbols, but this
5666
form is deprecated. Instead, you should depend on rules_python in your
57-
`WORKSPACE` file and load the Python rules from
58-
`@rules_python//python:defs.bzl`.
67+
`WORKSPACE` or `MODULE.bazel` file and load the Python rules from
68+
`@rules_python//python:defs.bzl` or load paths described in the API documentation.
5969

6070
A [buildifier](https://github.com/bazelbuild/buildtools/blob/master/buildifier/README.md)
6171
fix is available to automatically migrate `BUILD` and `.bzl` files to add the
@@ -66,13 +76,18 @@ appropriate `load()` statements and rewrite uses of `native.py_*`.
6676
buildifier --lint=fix --warnings=native-py <files>
6777
```
6878

69-
Currently, the `WORKSPACE` file needs to be updated manually as per [Getting
70-
started](getting-started).
79+
Currently, the `WORKSPACE` file needs to be updated manually as per
80+
[Getting started](getting-started).
7181

7282
Note that Starlark-defined bundled symbols underneath
7383
`@bazel_tools//tools/python` are also deprecated. These are not yet rewritten
7484
by buildifier.
7585

86+
## Migrating to bzlmod
87+
88+
See {gh-path}`Bzlmod support <BZLMOD_SUPPORT.md>` for any behaviour differences between
89+
`bzlmod` and `WORKSPACE`.
90+
7691

7792
```{toctree}
7893
:hidden:

0 commit comments

Comments
 (0)