Skip to content

Commit 91d66df

Browse files
committed
add some docs
1 parent e07a528 commit 91d66df

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

docs/toolchains.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ provide `Python.h`.
313313

314314
This is typically implemented using {obj}`py_cc_toolchain()`, which provides
315315
{obj}`ToolchainInfo` with the field `py_cc_toolchain` set, which is a
316-
{obj}`PyCcToolchainInfo` provider instance.
316+
{obj}`PyCcToolchainInfo` provider instance.
317317

318318
This toolchain type is intended to hold only _target configuration_ values
319319
relating to the C/C++ information for the Python runtime. As such, when defining
@@ -467,3 +467,35 @@ Currently the following flags are used to influence toolchain selection:
467467
* {obj}`--@rules_python//python/config_settings:py_linux_libc` for selecting the Linux libc variant.
468468
* {obj}`--@rules_python//python/config_settings:py_freethreaded` for selecting
469469
the freethreaded experimental Python builds available from `3.13.0` onwards.
470+
471+
## Accessing the underlying interpreter
472+
473+
To access the interpreter that bazel manages, you can use the
474+
`@rules_python//python/bin:interpreter` target. This is a binary target with
475+
the executable pointing at the `python3` binary plus the relevent runfiles.
476+
477+
```
478+
$ bazel run @rules_python//python/bin:interpreter
479+
Python 3.11.1 (main, Jan 16 2023, 22:41:20) [Clang 15.0.7 ] on linux
480+
Type "help", "copyright", "credits" or "license" for more information.
481+
>>>
482+
$ bazel run @rules_python//python/bin:interpreter --@rules_python//python/config_settings:python_version=3.12
483+
Python 3.12.0 (main, Oct 3 2023, 01:27:23) [Clang 17.0.1 ] on linux
484+
Type "help", "copyright", "credits" or "license" for more information.
485+
>>>
486+
```
487+
488+
You can also access a specific binary's interpreter this way by using the
489+
`@rules_python//python/bin:interpreter_src` target.
490+
491+
```
492+
$ bazel run @rules_python//python/bin:interpreter --@rules_python//python/bin:interpreter_src=//path/to:bin
493+
Python 3.11.1 (main, Jan 16 2023, 22:41:20) [Clang 15.0.7 ] on linux
494+
Type "help", "copyright", "credits" or "license" for more information.
495+
>>>
496+
```
497+
498+
:::{note}
499+
The interpreter target does not provide access to any modules from `py_*`
500+
targets on its own. Work is ongoing to support that.
501+
:::

tests/integration/interpreter_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def test_run_interpreter_3_12(self):
4444

4545
def _run_module_test(self, version):
4646
"""Validates that we can successfully invoke a module from the CLI."""
47+
# Pass unformatted JSON to the json.tool module.
4748
result = self.run_bazel(
4849
"run",
4950
f"--@rules_python//python/config_settings:python_version={version}",
@@ -53,6 +54,7 @@ def _run_module_test(self, version):
5354
"json.tool",
5455
input = '{"json":"obj"}',
5556
)
57+
# Validate that we get formatted JSON back.
5658
self.assert_result_matches(result, r'{\n "json": "obj"\n}')
5759

5860
def test_run_module_3_10(self):

0 commit comments

Comments
 (0)