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
* (toolchains) Run the check on the Python interpreter in isolated mode, to ensure it's not affected by userland environment variables, such as `PYTHONPATH`.
93
131
* (toolchains) Ensure temporary `.pyc` and `.pyo` files are also excluded from the interpreters repository files.
132
+
* (pypi) Run interpreter version call in isolated mode, to ensure it's not affected by userland environment variables, such as `PYTHONPATH`.
133
+
* (packaging) An empty `requires_file` is treated as if it were omitted, resulting in a valid `METADATA` file.
134
+
* (rules) py_wheel and sphinxdocs rules now propagate `target_compatible_with` to all targets they create.
Copy file name to clipboardExpand all lines: docs/toolchains.md
+98-5Lines changed: 98 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -199,10 +199,10 @@ Remember to call `use_repo()` to make repos visible to your module:
199
199
200
200
201
201
:::{deprecated} 1.1.0
202
-
The toolchain specific `py_binary` and `py_test` symbols are aliases to the regular rules.
202
+
The toolchain specific `py_binary` and `py_test` symbols are aliases to the regular rules.
203
203
i.e. Deprecated `load("@python_versions//3.11:defs.bzl", "py_binary")` & `load("@python_versions//3.11:defs.bzl", "py_test")`
204
204
205
-
Usages of them should be changed to load the regular rules directly;
205
+
Usages of them should be changed to load the regular rules directly;
206
206
i.e. Use `load("@rules_python//python:py_binary.bzl", "py_binary")` & `load("@rules_python//python:py_test.bzl", "py_test")` and then specify the `python_version` when using the rules corresponding to the python version you defined in your toolchain. {ref}`Library modules with version constraints`
207
207
:::
208
208
@@ -215,7 +215,11 @@ attribute. You can obtain the path to the Python interpreter using the
215
215
`$(PYTHON2)` and `$(PYTHON3)`["Make"
216
216
Variables](https://bazel.build/reference/be/make-variables). See the
for an example. We also make available `$(PYTHON2_ROOTPATH)` and `$(PYTHON3_ROOTPATH)`
219
+
which are Make Variable equivalents of `$(PYTHON2)` and `$(PYTHON3)` but for runfiles
220
+
locations. These will be helpful if you need to set env vars of binary/test rules
221
+
while using [`--nolegacy_external_runfiles`](https://bazel.build/reference/command-line-reference#flag--legacy_external_runfiles).
222
+
The original make variables still work in exec contexts such as genrules.
219
223
220
224
### Overriding toolchain defaults and adding more versions
221
225
@@ -327,7 +331,97 @@ After registration, your Python targets will use the toolchain's interpreter dur
327
331
is still used to 'bootstrap' Python targets (see https://github.com/bazel-contrib/rules_python/issues/691).
328
332
You may also find some quirks while using this toolchain. Please refer to [python-build-standalone documentation's _Quirks_ section](https://gregoryszorc.com/docs/python-build-standalone/main/quirks.html).
329
333
330
-
## Autodetecting toolchain
334
+
## Local toolchain
335
+
336
+
It's possible to use a locally installed Python runtime instead of the regular
337
+
prebuilt, remotely downloaded ones. A local toolchain contains the Python
338
+
runtime metadata (Python version, headers, ABI flags, etc) that the regular
339
+
remotely downloaded runtimes contain, which makes it possible to build e.g. C
340
+
extensions (unlike the autodetecting and runtime environment toolchains).
341
+
342
+
For simple cases, some rules are provided that will introspect
343
+
a Python installation and create an appropriate Bazel definition from
344
+
it. To do this, three pieces need to be wired together:
345
+
346
+
1. Specify a path or command to a Python interpreter (multiple can be defined).
347
+
2. Create toolchains for the runtimes in (1)
348
+
3. Register the toolchains created by (2)
349
+
350
+
The below is an example that will use `python3` from PATH to find the
351
+
interpreter, then introspect its installation to generate a full toolchain.
0 commit comments