astral-sh / rye

a Hassle-Free Python Experience
https://rye.astral.sh
MIT License
13.45k stars 459 forks source link

support dependency groups #421

Open Roger-luo opened 1 year ago

Roger-luo commented 1 year ago

I think this is a very convenient feature that pdm and poetry has. When I try to make a package that may use CUDA, I need to have a dependency that depends on hardware configurations, and a package manager has no means to know that thus I believe the best way is to let users decide which group of dependencies they should install. This is like the features at the package level.

Currently, there is no way to specify both CPU and GPU dependencies with rye within one pyproject.toml, cargo also has something similar that allows one to specify dependencies based on the current crates' features. And I don't see a way of passing "extra"s in python's pyproject.toml (e.g pass the extra [cuda12] across packages) I hope this could be something rye can fix

rbavery commented 6 months ago

It also would be great to be able to build wheels by specifying dependency groups. I want to build a CPU version of my package that uses the CPU version of pytorch, and another that uses the GPU version and also installs a few other packages. poetry doesn't support this even though it has dependency groups.

nikhilweee commented 1 month ago

Came here to say it would be nice to see this feature. Although I'm a bit confused as to what do we mean by dependency groups.

  1. Python projects already have a way of specifying extras under [project.optional-dependencies] in pyproject.toml. Is this what we are referring to?
  2. There's also a draft PEP-735 which is also called dependency groups. Although this talks about adding a top level [dependency-groups] table in pyproject.toml, amongst other things.

If we're referring to extras, I think rye already supports them. To add flask as an extra under the group web,

rye add flask --optional web

To add flask[async] as an extra / optional dependency under the group web,

rye add flask --features async --optional web

What's confusing is that if you need to do rye sync with the web extra included, you use --features instead of --optional.

rye sync --features web
sirfz commented 1 week ago
rye sync --features web

This actually doesn't work for me, must have something to do with a limitation in virtual packages (#639)