Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions crates/uv-pep508/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1276,6 +1276,38 @@ mod tests {
assert_eq!(*numpy.extras, [ExtraName::from_str("dev").unwrap()]);
}

#[test]
#[cfg(feature = "non-pep508-extensions")]
fn direct_url_display() -> Result<(), Box<dyn std::error::Error>> {
const URL: &str = "https://example.invalid/archive.whl?raw=%23#fragment";
let mut requirement = crate::UnnamedRequirement::<VerbatimUrl>::from_str(URL)?;
let cases: &[(&[&str], &str)] = &[
(&[], ""),
(&["dev"], "[dev]"),
(&["z", "a", "z"], "[z,a,z]"),
(&["B", "a_b", "B", "a.b"], "[b,a-b,b,a-b]"),
];
for (extras, suffix) in cases {
requirement.extras = extras
.iter()
.map(|name| ExtraName::from_str(name))
.collect::<Result<Vec<_>, _>>()?
.into_boxed_slice();
let expected = format!("{URL}{suffix}");
assert_eq!(requirement.to_string(), expected);
assert_eq!(requirement.to_string(), expected);
}

let requirement = crate::UnnamedRequirement::<VerbatimUrl>::from_str(
"https://user:fake-token@example.invalid/archive.whl?raw=%23#fragment[z,a,z] ; python_full_version >= '3.12'",
)?;
assert_eq!(
requirement.to_string(),
"https://user:****@example.invalid/archive.whl?raw=%23#fragment[z,a,z] ; python_full_version >= '3.12'"
);
Ok(())
}

#[test]
fn error_extras_eof1() {
assert_snapshot!(
Expand Down
12 changes: 3 additions & 9 deletions crates/uv-pep508/src/unnamed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use std::hash::Hash;
use std::path::Path;
use std::str::FromStr;

use itertools::Itertools;

use uv_fs::normalize_url_path;
use uv_normalize::ExtraName;

Expand Down Expand Up @@ -129,15 +131,7 @@ impl<Url: UnnamedRequirementUrl> Display for UnnamedRequirement<Url> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.url)?;
if !self.extras.is_empty() {
write!(
f,
"[{}]",
self.extras
.iter()
.map(ToString::to_string)
.collect::<Vec<_>>()
.join(",")
)?;
write!(f, "[{}]", self.extras.iter().format(","))?;
}
if let Some(marker) = self.marker.contents() {
write!(f, " ; {marker}")?;
Expand Down
Loading