@@ -313,7 +313,7 @@ provide `Python.h`.
313313
314314This 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
318318This toolchain type is intended to hold only _ target configuration_ values
319319relating 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+ :::
0 commit comments