//python:py_exec_tools_info.bzl
Provider for the exec tools toolchain.
See also
Custom toolchains for how to define custom toolchains.
py_cc_toolchainrule for defining the toolchain.
- provider PyExecToolsInfo
Build tools used as part of building Python programs.
- PyExecToolsInfo.<init>(exec_interpreter, precompiler)
- PyExecToolsInfo.exec_interpreter: Target | None
If available, an interpreter valid for running in the exec configuration. When running it in an action, use
DefaultInfo.files_to_runto ensure all its files are appropriately available. An exec interpreter may not be available, e.g. if all the exec tools are prebuilt binaries.Note
this interpreter is really only for use when a build tool cannot use the Python toolchain itself. When possible, prefeer to define a
py_binaryinstead and use it via acfg=execattribute; this makes it much easier to setup the runtime environment for the binary. See also:py_interpreter_programrule.Note
What interpreter is used depends on the toolchain constraints. Ensure the proper target constraints are being applied when obtaining this from the toolchain.
Warning
This does not work correctly in case of RBE, please use exec_runtime instead.
Once https://github.com/bazelbuild/bazel/issues/23620 is resolved this warning may be removed.
- PyExecToolsInfo.precompiler: Target | None
If available, the tool to use for generating pyc files. If not available, precompiling will not be available.
Must provide one of the following:
PyInterpreterProgramInfo
DefaultInfo.files_to_run
This target provides either the
PyInterpreterProgramInfoprovider or is a regular executable binary (provides DefaultInfo.files_to_run). When thePyInterpreterProgramInfoprovider is present, it means the precompiler program doesn’t know how to find the interpreter itself, so the caller must provide it when constructing the action invocation for running the precompiler program (typicallyexec_interpreter). See thePyInterpreterProgramInfoprovider docs for details on how to construct an invocation.If
testing.ExecutionInfois provided, it will be used to set execution requirements. This can be used to control persistent worker settings.The precompiler command line API is:
--invalidation_mode: The type of pyc invalidation mode to use. Should be one ofunchecked_hashorchecked_hash.--optimize: The optimization level as an integer.--python_version: The Python version, inMajor.Minorformat, e.g.3.12
The following args are repeated and form a list of 3-tuples of their values. At least one 3-tuple will be passed.
--src: Path to the source.pyfile to precompile.--src_name: The human-friendly file name to record in the pyc output.--pyc: Path to where pyc output should be written.
NOTE: These arguments may be stored in a file instead, in which case, the path to that file will be a positional arg starting with
@, e.g.@foo/bar. The format of the file is one arg per line.