Bazel Pypi 宏自边缘



我磕磕绊绊地试图让 bazel 使用 pypi 依赖项。

./pypi.bzl:

def _impl(ctx):
ctx.actions.run_shell(
command = "pip download %s" % ctx.package
)
_pypi_package = rule(
implementation=_impl,
attrs={"package": attr.label(mandatory=True)},
)
def pypi_package(package):
_pypi_package(name = package, package = package)

。/建:

py_binary(
name = "app",
srcs = ["app.py"],
deps = [":python-dateutil"]
)
load("//:pypi.bzl", "pypi_package")
pypi_package(
package="python-dateutil",
)

尝试构建:

$ bazel build app
ERROR: /path/to/cwd/BUILD:9:1: in _pypi_package rule //:python-dateutil: cycle in dependency graph:
//:app
.-> //:python-dateutil [self-edge]
`--
This cycle occurred because of a configuration option.
ERROR: Analysis of target '//:app' failed; build aborted.
INFO: Elapsed time: 0.219s

不知道这是否是使用外部依赖项的正确方法,但忽略了这一点,我不明白这里的 self-dep 来自哪里。事实上,我根本没有看到我为pypi_package规则声明任何 deps。这是怎么回事?

问题是attr.label:"标签"在这里意味着构建标签。我应该使用attr.string.

相关内容

  • 没有找到相关文章

最新更新