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
argsattribute is only used with thebazel runcommand: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
genruleor a custom Starlark rule. Something like:then you would build the output of the genrule:
bazel build mock_outputor use the output of the genrule as an input to another target