How to define and use Python requirements for dev/testing?

56 views
Skip to first unread message

Haixin Tie

unread,
May 23, 2024, 11:43:24 PMMay 23
to bazel-discuss
Hi Python build rule experts,

I was able to follow the official rules_python example to use 3rd party dependencies in Bazel as defined in requirements.in here:

https://github.com/bazelbuild/rules_python/tree/main/examples/multi_python_versions

But nowhere can I find how to define and use requirements-dev.in in Bazel (with additional libs only for dev and testing). Does anybody have any pointers on how to do that?

For regular requirements, I see this line works:

load("@pypi//:requirements.bzl", "requirement")

But it's not obvious how rules_python generates "requirement", so it's unclear to me how to do the similar thing for requirement-dev. I'd appreciate your guidance!

Regards,
HaiXin

zhang kai

unread,
May 25, 2024, 1:48:59 PMMay 25
to bazel-discuss
I don't use rules_python a lot, so I might be wrong. You can put all your dependencies (including testing-only dependencies) in a single requirement file.

Then you can still define separate dependencies in the py_binary and py_test targets. For example, you can put the pytest lib in the requirement file, then only put it in all the py_test targets not py_binary targets.
Reply all
Reply to author
Forward
0 new messages