Consider I have a py_binary :
py_binary(
name = "mock",
srcs = ["mock.py"],
args = [
"$(location @mockref//mockpackage)",
],
data = [
"@mockref//:mockfile",
],
deps = [
requirement("somerequirement"),
],
)
If mock.py accept a command line argument named --somearg
using argument parser how can I pass this argument through the args field in bazel file without passing the argument in bazel build
command?
The
args
attribute is only used with thebazel run
command:https://docs.bazel.build/versions/main/be/common-definitions.html#binary.args
To run a binary as part of a build, typically you'd use a
genrule
or a custom Starlark rule. Something like:then you would build the output of the genrule:
bazel build mock_output
or use the output of the genrule as an input to another target