Allow dashes and underscores in custom index names (#8339)

Previously, `uv add --index` command threw an error when the index name
included characters like hyphens or underscores.

Closes #8315
This commit is contained in:
Vini Brasil 2024-10-18 14:24:16 -03:00 committed by GitHub
parent c162078050
commit 69d5e084d5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 1 deletions

View file

@ -158,7 +158,10 @@ impl FromStr for Index {
return Err(IndexSourceError::EmptyName);
}
if name.chars().all(char::is_alphanumeric) {
if name
.chars()
.all(|c| c.is_alphanumeric() || c == '-' || c == '_')
{
let url = IndexUrl::from_str(url)?;
return Ok(Self {
name: Some(name.to_string()),

View file

@ -18,6 +18,8 @@ name = "pytorch"
url = "https://download.pytorch.org/whl/cpu"
```
Index names must only contain alphanumeric characters, dashes, or underscores.
Indexes are prioritized in the order in which theyre defined, such that the first index listed in
the configuration file is the first index consulted when resolving dependencies, with indexes
provided via the command line taking precedence over those in the configuration file.