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
feat(bzlmod): Register a default toolchain (#1259)
This makes rules_python always provide a default toolchain when using
bzlmod.
Note that, unlike workspace builds, the default is not the local
system Python (`@bazel_tools//tools/python:autodetecting_toolchain`).
Instead, the default is a hermetic runtime, but no guarantees are made
about the particular version used. In practice, it will be the latest
available Python version.
Work towards #1233
Copy file name to clipboardExpand all lines: BZLMOD_SUPPORT.md
+24Lines changed: 24 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,3 +35,27 @@ This rule set does not have full feature partity with the older `WORKSPACE` type
35
35
2. Gazelle does not support finding deps in sub-modules. For instance we can have a dep like ` "@our_other_module//other_module/pkg:lib",` in a `py_test` definition.
36
36
37
37
Check ["issues"](/bazelbuild/rules_python/issues) for an up to date list.
38
+
39
+
## Differences in behavior from WORKSPACE
40
+
41
+
### Default toolchain is not the local system Python
42
+
43
+
Under bzlmod, the default toolchain is no longer based on the locally installed
44
+
system Python. Instead, a recent Python version using the pre-built,
45
+
standalone runtimes are used.
46
+
47
+
If you need the local system Python to be your toolchain, then it's suggested
48
+
that you setup and configure your own toolchain and register it. Note that using
49
+
the local system's Python is not advised because will vary between users and
50
+
platforms.
51
+
52
+
If you want to use the same toolchain as what WORKSPACE used, then manually
53
+
register the builtin Bazel Python toolchain by doing
Copy file name to clipboardExpand all lines: README.md
+29-8Lines changed: 29 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -45,31 +45,52 @@ the older way of configuring bazel with a `WORKSPACE` file.
45
45
46
46
### Using bzlmod
47
47
48
+
NOTE: bzlmod support is still experimental; APIs subject to change.
49
+
48
50
To import rules_python in your project, you first need to add it to your
49
51
`MODULE.bazel` file, using the snippet provided in the
50
52
[release you choose](https://github.com/bazelbuild/rules_python/releases).
51
53
54
+
Once the dependency is added, a Python toolchain will be automatically
55
+
registered and you'll be able to create runnable programs and tests.
56
+
57
+
52
58
#### Toolchain registration with bzlmod
53
59
54
-
To register a hermetic Python toolchain rather than rely on a system-installed interpreter for runtime execution, you can add to the `MODULE.bazel` file:
60
+
NOTE: bzlmod support is still experimental; APIs subject to change.
61
+
62
+
A default toolchain is automatically configured for by depending on
63
+
`rules_python`. Note, however, the version used tracks the most recent Python
64
+
release and will change often.
65
+
66
+
If you want to register specific Python versions, then use
67
+
`python.toolchain()` for each version you need:
55
68
56
69
```starlark
57
-
# Find the latest version number here: https://github.com/bazelbuild/rules_python/releases
58
-
# and change the version number if needed in the line below.
0 commit comments