From 69d5e084d5e70be0ee8cf0066cd12274ab464ddc Mon Sep 17 00:00:00 2001 From: Vini Brasil Date: Fri, 18 Oct 2024 14:24:16 -0300 Subject: [PATCH] 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 --- crates/uv-distribution-types/src/index.rs | 5 ++++- docs/configuration/indexes.md | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/uv-distribution-types/src/index.rs b/crates/uv-distribution-types/src/index.rs index 3e90bacf4ef6..0d04c9a517f9 100644 --- a/crates/uv-distribution-types/src/index.rs +++ b/crates/uv-distribution-types/src/index.rs @@ -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()), diff --git a/docs/configuration/indexes.md b/docs/configuration/indexes.md index 18b6c9d17535..a16087eacfa5 100644 --- a/docs/configuration/indexes.md +++ b/docs/configuration/indexes.md @@ -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 they’re 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.