Skip to content
Merged
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
29 changes: 15 additions & 14 deletions crates/uv-platform-tags/src/abi_tag.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::borrow::Cow;
use std::fmt::{Display, Formatter, Write};
use std::ops::{Deref, DerefMut};
use std::str::FromStr;
Expand Down Expand Up @@ -136,11 +137,11 @@ impl AbiTag {
}

/// Return a pretty string representation of the ABI tag.
pub fn pretty(self) -> Option<String> {
pub fn pretty(self) -> Option<Cow<'static, str>> {
match self {
Self::None => None,
Self::Abi3 => None,
Self::Abi3T => Some("stable ABI for free-threaded CPython".to_string()),
Self::Abi3T => Some(Cow::Borrowed("stable ABI for free-threaded CPython")),
Self::CPython {
variant,
python_version,
Expand All @@ -156,26 +157,26 @@ impl AbiTag {
} else {
""
};
Some(format!(
Some(Cow::Owned(format!(
"{}CPython {}.{}",
prefix, python_version.0, python_version.1
))
)))
}
Self::PyPy {
implementation_version,
..
} => Some(format!(
} => Some(Cow::Owned(format!(
"PyPy {}.{}",
implementation_version.0, implementation_version.1
)),
))),
Self::GraalPy {
implementation_version,
..
} => Some(format!(
} => Some(Cow::Owned(format!(
"GraalPy {}.{}",
implementation_version.0, implementation_version.1
)),
Self::Pyston { .. } => Some("Pyston".to_string()),
))),
Self::Pyston { .. } => Some(Cow::Borrowed("Pyston")),
}
}
}
Expand Down Expand Up @@ -489,24 +490,24 @@ mod tests {
assert_eq!(AbiTag::Abi3T.to_string(), "abi3t");
assert!(AbiTag::Abi3T.is_stable_abi());
assert_eq!(
AbiTag::Abi3T.pretty(),
Some("stable ABI for free-threaded CPython".to_string())
AbiTag::Abi3T.pretty().as_deref(),
Some("stable ABI for free-threaded CPython")
);
}

#[test]
fn cpython_abi() {
let tag = AbiTag::from_str("cp39").unwrap();
assert_eq!(tag.to_string(), "cp39");
assert_eq!(tag.pretty(), Some("CPython 3.9".to_string()));
assert_eq!(tag.pretty().as_deref(), Some("CPython 3.9"));

let tag = AbiTag::from_str("cp37m").unwrap();
assert_eq!(tag.to_string(), "cp37m");
assert_eq!(tag.pretty(), Some("CPython 3.7".to_string()));
assert_eq!(tag.pretty().as_deref(), Some("CPython 3.7"));

let tag = AbiTag::from_str("cp313t").unwrap();
assert_eq!(tag.to_string(), "cp313t");
assert_eq!(tag.pretty(), Some("free-threaded CPython 3.13".to_string()));
assert_eq!(tag.pretty().as_deref(), Some("free-threaded CPython 3.13"));

assert_eq!(
AbiTag::from_str("cpXY"),
Expand Down
Loading