我幾乎失去了努力創建一個自定義庫中的規則......如何設置基本的repository_rule?
pypi.bzl
:
def _impl(repository_ctx):
repository_ctx.execute(['echo', '"testing testing 123"'])
repository_ctx.execute(['pip', 'download', repository_ctx.attr.package])
repository_ctx.file("BUILD",
"""
py_library(
name = "lib",
srcs = glob(["*.py"]),
)
""")
pypi_package = repository_rule(
implementation=_impl,
attrs={"package": attr.string(mandatory=True)},
)
WORKSPACE
:
load("//:pypi.bzl", "pypi_package")
pypi_package(
name = "dateutil",
package = "python-dateutil",
)
BUILD
:
py_binary(
name = "app",
srcs = ["app.py"],
deps = ["@dateutil//lib"],
)
$ bazel build app
ERROR: /Users/alec/code/bazel-pypi/BUILD:1:1: no such package '@dateutil//lib': BUILD file not found on package path and referenced by '//:app'.
ERROR: Analysis of target '//:app' failed; build aborted.
我我不知道如何開始調試問題是因爲它似乎不像我的存儲庫規則的實現中的命令甚至可以運行。 (例如,從echo
沒有輸出)。顯然不會有一個library
目標如果repository_ctx.file
呼叫沒有發生......