astral-sh / uv

An extremely fast Python package and project manager, written in Rust.
https://docs.astral.sh/uv
Apache License 2.0
25.6k stars 747 forks source link

specifying single-package indices with uv add --index #8341

Open itrase opened 2 weeks ago

itrase commented 2 weeks ago

The new --index functionality makes it possible to do this: uv init uv add torch --index pytorch=https://download.pytorch.org/whl/cu121 and get a reproducable toml file, which is really nice. Is there a way to specify through the command line that torch should be the only project that uses that index, and all the others should use the default (pypi)? As an example, if I then call: uv add fsspec This installs an old version present on the pytorch index, rather than the newer one in pypi. I could just add unsafe-best-match, but I'd prefer not to. As an alternative, is there a way to tell uv that I want to install a particular package from the default index? Something like: uv add fsspec --index default ? That doesn't feel quite as good but would probably be a solution 90% of the time.

charliermarsh commented 2 weeks ago

You can change the index definition to:

[[tool.uv.index]]
name = "pytorch"
url = "https://download.pytorch.org/whl/cu121"
explicit = true

Then, the index will only be used by that package.

We don't have a way to do this via the CLI-only though, you have to add explicit = true to the TOML. I wonder what a good API would look like for that (--explicit-index)?

itrase commented 2 weeks ago

ah thank you! explicit solves the problem for now. And I think a CLI flag like --explicit-index would work totally fine.