uv
7e6caa45 - Support referencing indexes by name via `--index` and `--default-index` (#17455)

Commit
47 days ago
Support referencing indexes by name via `--index` and `--default-index` (#17455) ## Summary Implement #13974. This PR makes `uv ... --index name` attempt to look up the index by name in filesystem configuration (workspace `pyproject.toml` or adjacent `uv.toml` (for project commands), then user config, then system config). The only difference is that the index will be passed with `explicit` and `default` set to `false` for that invocation. Additionally, `uv ... --default-index name` acts in the same way, except the `default` setting is forcibly set to `true`. This will work for `uv add --index name package...` pinning, with the same caveats that already apply when doing `uv add --index name=<location> package...`. Without `--preview-features index-by-name`, named index references will prefer a directory of the same name, it will continue to warn about the potential ambiguity (now with all invocations, not just `uv add`). In case no index or directory of that name exists, the existing error will be emitted. Lastly, if only an index of that name exists, it will be resolved with a preview warning. With `--preview-features index-by-name`, named index references will prefer an index of that name over any directory, but will continue to resolve to directories (with a warning as usual). In case no index or directory of that name exists, a new `index name` focused error will be emitted. There are fundamental quirks with how `--index` and `--default-index` interact with `uv add` which mean this feature doesn't fully work as we would like. Expect some changes before it stabilises. ## Test Plan A number of relevant tests have been added. They're trying to strike a balance between abstraction and simplicity. I found it was easier to keep track of what was actually being tested if you didn't have to dig through a haystack of setup code and snapshot every time you glanced at the tests.
Author
Parents
Loading