Add index URLs when provided via uv add --index or --default-index (#7746)

## Summary

The behavior is as follows:

- If you provide `--index` or `--default-index` on the command-line, we
add those indexes to the `pyproject.toml` (with names, if provided, as
in `--index pytorch=https://download.pytorch.org/whl/cu121`.
- If you provide `--index-url` or `--default-index`, we warn, but don't
add the indexes to the file. (This seems wrong -- why not add them?)
- If you provide an index with a name or URL that already exists, we
remove that entry, and add the new index to the top of the list (since
it now has highest priority).
- If you provide a `--default-index`, and an index already has `default
= true`, we remove that entry, since it won't be used anymore.

We do _not_ pin packages to specific indexes yet.
This commit is contained in:
Charlie Marsh 2024-10-15 15:57:26 -07:00 committed by GitHub
parent 1925922770
commit ad24cee7c6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 1037 additions and 5 deletions

View file

@ -768,6 +768,10 @@ impl<T> Maybe<T> {
Maybe::None => None,
}
}
pub fn is_some(&self) -> bool {
matches!(self, Maybe::Some(_))
}
}
/// Parse a string into an [`IndexUrl`], mapping the empty string to `None`.