Skip to content

Commit ad94a0e

Browse files
committed
add an example to the docs
1 parent 02f1862 commit ad94a0e

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

docs/toolchains.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,43 @@ existing attributes:
184184
* Adding additional Python versions via {bzl:obj}`python.single_version_override` or
185185
{bzl:obj}`python.single_version_platform_override`.
186186

187+
### Using defined toolchains from WORKSPACE
188+
189+
It is possible to use toolchains defined in `MODULE.bazel` in `WORKSPACE`. For example
190+
the following `MODULE.bazel` and `WORKSPACE` provides a working {bzl:obj}`pip_parse` setup:
191+
```starlark
192+
# WORKSPACE contents
193+
load("@rules_python//python:repositories.bzl", "py_repositories")
194+
195+
py_repositories()
196+
197+
load("@rules_python//python:pip.bzl", "pip_parse")
198+
199+
pip_parse(
200+
name = "third_party",
201+
requirements_lock = "//:requirements.txt",
202+
python_interpreter_target = "@python_3_10_host//:python",
203+
)
204+
205+
load("@third_party//:requirements.bzl", "install_deps")
206+
207+
install_deps()
208+
209+
# MODULE.bazel contents
210+
bazel_dep(name = "rules_python", version = "0.40.0")
211+
212+
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
213+
214+
python.toolchain(is_default = True, python_version = "3.10")
215+
216+
use_repo(python, "python_3_10", "python_3_10_host")
217+
```
218+
219+
Note, the user has to import the `*_host` repository to use the python interpreter in the
220+
{bzl:obj}`pip_parse` and {bzl:obj}`whl_library` repository rules and once that is done
221+
users should be able to ensure the setting of the default toolchain even during the
222+
transition period when some of the code is still defined in `WORKSPACE`.
223+
187224
## Workspace configuration
188225

189226
To import rules_python in your project, you first need to add it to your

0 commit comments

Comments
 (0)