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

Skip to first unread message

Haixin Tie

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 here:

But nowhere can I find how to define and use 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!


zhang kai

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
0 new messages