PyRuntime 資訊

回報問題 查看來源 Nightly

包含 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 string;必要
新物件的 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

如果這是內部執行階段,這個欄位會是代表解譯器的 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

執行 py_binary 目標時,在使用的 Python 虛設常式指令碼前方加上「Shebang」運算式。不適用於 Windows。