让 Bazel 使用 python 3
make Bazel use python 3
我想 运行 我的 py_test 和 Bazel 中的 python 3。
py_library(
name = "foo",
srcs = ["foo.py"]
)
py_test(
name = "foo_test",
srcs = glob(["foo_test.py",]),
deps = [":foo"]
)
py_runtime(
name = "python-3.6.3",
files = [],
interpreter_path = "/usr/local/bin/python3",
)
我可以使用命令实现这个
bazel test --python_top=//path/to/foo:python-3.6.3 foo_test
但是,我想使用 new_http_archive 将 python3 导入到 bazel 沙盒中,并为指向 [=24] 的 py_runtime 规则提供 interpreter_path =] 在 bazel 沙箱中。到目前为止,我无法找到什么是 interpreter_path...我是否必须在 py_runtime 或其他地方的某处引用 http_archive 标签?
new_http_archive(
name = "python_version",
urls = ["https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz"],
strip_prefix = "Python-3.6.3",
build_file_content = """
py_library(
name = "python_srcs",
srcs = glob(["Lib/*.py"]),
visibility = ["//visibility:public"]
)"""
)
您正在下载的 tgz 不包含解释器。它包含解释器的源代码。如果你想构建解释器作为构建的一部分,你可以做这样的事情
new_http_archive(
name = "python_version",
urls = ["https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz"],
strip_prefix = "Python-3.6.3",
build_file_content = """
genrule(
name = "build_python",
srcs = glob(["**"]),
outs = ["python"],
cmd = "./external/python_version/configure && make && cp python $@",
visibility = ["//visibility:public"],
)""",
)
然后您的 py_runtime 规则将设置 interpreter
属性(而不是 interpreter_path):
py_runtime(
name = "python-3.6.3",
files = [],
interpreter = "@python_version//:python",
)
我想 运行 我的 py_test 和 Bazel 中的 python 3。
py_library(
name = "foo",
srcs = ["foo.py"]
)
py_test(
name = "foo_test",
srcs = glob(["foo_test.py",]),
deps = [":foo"]
)
py_runtime(
name = "python-3.6.3",
files = [],
interpreter_path = "/usr/local/bin/python3",
)
我可以使用命令实现这个
bazel test --python_top=//path/to/foo:python-3.6.3 foo_test
但是,我想使用 new_http_archive 将 python3 导入到 bazel 沙盒中,并为指向 [=24] 的 py_runtime 规则提供 interpreter_path =] 在 bazel 沙箱中。到目前为止,我无法找到什么是 interpreter_path...我是否必须在 py_runtime 或其他地方的某处引用 http_archive 标签?
new_http_archive(
name = "python_version",
urls = ["https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz"],
strip_prefix = "Python-3.6.3",
build_file_content = """
py_library(
name = "python_srcs",
srcs = glob(["Lib/*.py"]),
visibility = ["//visibility:public"]
)"""
)
您正在下载的 tgz 不包含解释器。它包含解释器的源代码。如果你想构建解释器作为构建的一部分,你可以做这样的事情
new_http_archive(
name = "python_version",
urls = ["https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz"],
strip_prefix = "Python-3.6.3",
build_file_content = """
genrule(
name = "build_python",
srcs = glob(["**"]),
outs = ["python"],
cmd = "./external/python_version/configure && make && cp python $@",
visibility = ["//visibility:public"],
)""",
)
然后您的 py_runtime 规则将设置 interpreter
属性(而不是 interpreter_path):
py_runtime(
name = "python-3.6.3",
files = [],
interpreter = "@python_version//:python",
)