Description
Hi there, I'll preface this by saying this is super low priority -- I'm not really using will.py
for anything important. And I'm probably doing something very weird that nobody else is. Just wanted to report.
I'm trying to use bazel to run a bunch of beancount scripts. Mostly this is straightforward.
But I'm having some trouble using https://github.com/beancount/beanlabs/blob/master/beanlabs/will/will.py.
Problem number 1: will.py
has a main
function, but is not exposed as a py_binary
in the BUILD rule. That's probably fairly straightforward to fix.
Problem number 2: Build visibility.
The BUILD file (https://github.com/beancount/beanlabs/blob/master/beanlabs/will/BUILD) refers to targets in //beancount
:
py_library(
name = "will",
srcs = ["will.py"],
deps = [
"//beancount/core:account",
...
],
)
//beancount
maybe used to be accessible when beanlabs was a subfolder of the main beancount repository. But now it's in a different repository, and we need to import and rename them via a WORKSPACE
file like this:
git_repository(
name = "bc",
remote = "https://github.com/beancount/beancount.git",
commit = "5adf7b9a3be99f631f4b8cd161287f1479dce377",
shallow_since = "1616264925 -0400",
)
And then access them with the renamed name, like "@//beancount/core:account"
.
So I'm doing this, by writing my own BUILD.beanlabs
file:
load("@rules_python//python:defs.bzl", "py_binary")
package(
default_visibility = ["//visibility:public"],
)
# Can't use the existing build rules because they assume beanlabs will be run from inside beancount
py_binary(
name = "will",
srcs = ["//beanlabs/will:will.py"],
deps = [
"@bc//beancount/core:account",
"@bc//beancount/core:account_types",
"@bc//beancount/core:convert",
"@bc//beancount/core:data",
"@bc//beancount/core:getters",
"@bc//beancount/core:realization",
"@bc//beancount:loader",
"@bc//beancount/parser:options",
"@bc//beancount/parser:version",
],
)
But then that fails due to BUILD visibility of the depended targets:
$ bazel test ...
ERROR: /private/var/tmp/_bazel_mark/c85e0696457b3a2f404f0721275052b4/external/beanlabs/BUILD.bazel:8:10: in py_binary rule @beanlabs//:will: target '@bc//beancount/core:account' is not visible from target '@beanlabs//:will'. Check the visibility declaration of the former target if you think the dependency is legitimate
ERROR: /private/var/tmp/_bazel_mark/c85e0696457b3a2f404f0721275052b4/external/beanlabs/BUILD.bazel:8:10: in py_binary rule @beanlabs//:will: target '@bc//beancount/core:account_types' is not visible from target '@beanlabs//:will'. Check the visibility declaration of the former target if you think the dependency is legitimate
ERROR: /private/var/tmp/_bazel_mark/c85e0696457b3a2f404f0721275052b4/external/beanlabs/BUILD.bazel:8:10: in py_binary rule @beanlabs//:will: target '@bc//beancount/core:convert' is not visible from target '@beanlabs//:will'. Check the visibility declaration of the former target if you think the dependency is legitimate
ERROR: /private/var/tmp/_bazel_mark/c85e0696457b3a2f404f0721275052b4/external/beanlabs/BUILD.bazel:8:10: in py_binary rule @beanlabs//:will: target '@bc//beancount/core:data' is not visible from target '@beanlabs//:will'. Check the visibility declaration of the former target if you think the dependency is legitimate
ERROR: /private/var/tmp/_bazel_mark/c85e0696457b3a2f404f0721275052b4/external/beanlabs/BUILD.bazel:8:10: in py_binary rule @beanlabs//:will: target '@bc//beancount/core:getters' is not visible from target '@beanlabs//:will'. Check the visibility declaration of the former target if you think the dependency is legitimate
ERROR: /private/var/tmp/_bazel_mark/c85e0696457b3a2f404f0721275052b4/external/beanlabs/BUILD.bazel:8:10: in py_binary rule @beanlabs//:will: target '@bc//beancount/core:realization' is not visible from target '@beanlabs//:will'. Check the visibility declaration of the former target if you think the dependency is legitimate
ERROR: /private/var/tmp/_bazel_mark/c85e0696457b3a2f404f0721275052b4/external/beanlabs/BUILD.bazel:8:10: Analysis of target '@beanlabs//:will' failed
Indeed, the default visibility of beancount.core is fairly restrictive: https://github.com/beancount/beancount/blob/master/beancount/core/BUILD#L2
According to bazelbuild/bazel#3744, if you want visibility cross-repo, the only supported visibility is //visibility:public
.
In the meantime, I'm working around this by specifying --nocheck_visibility
. But it would be neat to avoid this :-)
I'm not sure, but I think there's an argument that beancount.core
is part of the "public API" of beancount, depended on by anyone importing beancount, so maybe it should also be //visibility:public
?
I'm guessing this beanlabs BUILD code is fairly vestigial (as there's no WORKSPACE in the repo).
I don't really expect you to fix this for me -- I'm happy to help contribute some fixes, just wanted to start a conversation about the desired state here.
Activity