PyRuntimeInfo

报告问题 查看源代码

包含 py_runtime 规则返回的 Python 运行时信息。

Python 运行时描述的是平台运行时或构建中的运行时。平台运行时访问位于已知路径的系统安装的解释器,而构建中的运行时指向充当解释器的 File。在这两种情况下,“解释器”实际上是指能够运行在命令行上传递的 Python 脚本的任何可执行二进制文件或封装容器脚本,并遵循与标准 CPython 解释器相同的惯例。

成员

PyRuntimeInfo

PyRuntimeInfo PyRuntimeInfo(interpreter_path=None, interpreter=None, files=None, coverage_tool=None, coverage_files=None, python_version, stub_shebang=None, bootstrap_template=None)

PyRuntimeInfo 构造函数。

参数

参数 说明
interpreter_path string;或 None;默认值为 None
新对象的 interpreter_path 字段的值。如果您传入 interpreter,请勿为此参数提供值。
interpreter File;或 None;默认值为 None
新对象的 interpreter 字段的值。如果您传入 interpreter_path,请勿为此参数提供值。
files Filedepset;或 None;默认值为 None
新对象的 files 字段的值。如果您传入 interpreter_path,请勿为此参数提供值。如果指定了 interpreter 且此参数为 None,则 files 会变为空的 depset
coverage_tool File;或 None;默认值为 None
新对象的 coverage_tool 字段的值。
coverage_files Filedepset;或 None;默认值为 None
新对象的 coverage_files 字段的值。如果您未同时传入 coverage_tool,请勿为此参数指定值。
python_version required
新对象的 python_version 字段的值。
stub_shebang string;默认值为 None
新对象的 stub_shebang 字段的值。如果 None 或未指定,则系统会使用 #!/usr/bin/env python3
bootstrap_template File;或 None;默认值为 None

bootstrap_template

File PyRuntimeInfo.bootstrap_template

要使用的存根脚本模板文件。应包含 %python_binary%、%workspace_name%、%main% 和 %imports%。如需查看更多变量,请参阅 @bazel_tools//tools/python:python_bootstrap_template.txt。

coverage_files

depset PyRuntimeInfo.coverage_files

在运行时使用 coverage_tool 所需的文件。如果未提供 coverage_tool,值将为 None。 可能会返回 None

coverage_tool

File PyRuntimeInfo.coverage_tool

如果设置了此字段,则它是一个 File,表示用于从 Python 测试收集代码覆盖率信息的工具。否则为 None。 可能会返回 None

文件

depset PyRuntimeInfo.files

如果这是构建运行时,则此字段是 Filedepset,需要添加到使用此运行时的可执行目标的运行文件(特别是 interpreter 所需的文件)。此字段中无需包含 interpreter 的值。如果这是平台运行时,则此字段为 None。 可能会返回 None

口译

File PyRuntimeInfo.interpreter

如果这是 build 内运行时,则此字段是表示解释器的 File。否则,其值为 None。请注意,构建中的运行时可以使用预构建的签入解释器,也可以使用在源代码的基础上构建的解释器。 可能会返回 None

interpreter_path

string PyRuntimeInfo.interpreter_path

如果这是平台运行时,则此字段是目标平台上解释器的绝对文件系统路径。否则为 None。 可能会返回 None

python_version

string PyRuntimeInfo.python_version

指示此运行时使用的是 Python 主要版本 2 还是 3。有效值为(仅限)"PY2""PY3"

stub_shebang

string PyRuntimeInfo.stub_shebang

“Shebang”表达式,位于执行 py_binary 目标时使用的引导式 Python 存根脚本前面。不适用于 Windows。