Review for --index <name> support#18956
Conversation
… -> `pyproject.toml`
| let mut index = index.borrow().clone(); | ||
| // A named index selected via `--index <name>` should behave like any | ||
| // other explicit CLI index, regardless of whether it was marked as a | ||
| // config-level default. | ||
| index.default = false; |
There was a problem hiding this comment.
Maybe this is a good approach to handling explicit indexes too?
If you pass one to uv add it preserves whatever was set, but if you pass multiple to uv add or any to other commands, we treat them as normal indexes?
It would save all that error handling.
There was a problem hiding this comment.
Multiple explicit indexes?
There was a problem hiding this comment.
I mean specifically passing multiple indexes where at least one of them is explicit.
There was a problem hiding this comment.
I think that sounds too confusing.
| bail!( | ||
| "Index `{index_name}` was found in a project-level `uv.toml`, but `uv add` cannot persist it to `tool.uv.sources`. Define the index in the project's `pyproject.toml` first, or use `--raw`." | ||
| ); |
There was a problem hiding this comment.
If manually persisting it would work, why would automatically persisting it be broken?
Alternatively, if automatically persisting it is broken, then why would manually persisting it work?
There was a problem hiding this comment.
This error message needs to be improved (or, we can allow it — but it's weird)
There was a problem hiding this comment.
Okay, to summarise the discussion we had on this topic:
The root cause is likely that the indexes from a pyproject.toml adjacent uv.toml are marked as having the Project origin, and this is what is used to determine if the index should be written back. But, we don't read that same uv.toml to pick up tool.uv.sources indexes (one of the reason why we write back other named indexes).
To make this work, we would need to distinguish between indexes from a pyproject.toml adjacent uv.toml when persisting.
Alternatively, we don't allow index definitions from a pyproject.toml adjacent uv.toml to be picked up by name at all.
Maybe the idea here would be that a pyproject.toml adjacent uv.toml shouldn't be allowed to have indexes? I initially thought nothing could use these without --index <name> anyway but I am actually not so sure any more.
The other option is to keep this error in this place, but to word it slightly better. Although I think the heuristic could still avoid this overhead of checking the index against the existing ones manually.
2b4ae4c to
3c1dabe
Compare
Review of #17455
Addressed my comments there, as well as some edge cases I found:
uv.tomlcontains an index anduv add --index namewas used, we would add thetool.uv.sourcesentry but subsequent resolutions would fail because source entries require a co-located index definition. The fix chosen here is to fail instead with a helpful error message.--index foowas used, we would fail immediately if foo was not a known index name. This regressed the existing behavior, where we'd expectfooto be a directory. The fix chosen here was to retain the existing behavior and warn that we'd require./fooin the future.--index namewas used and name referred to an index withdefault = true, we did not toggle the default flag and the index was still considered lowest priority. The resolution chosen here was to move the index priority by unsetting the default flag, such that it would be equivalent to--index <url>.--index namewith a workspace member as a working directory, we would not load find indexes defined in the workspace member — we'd require--package membertoo. The fix chosen here was to load workspace member indexes for the working directory.