Skip to content
Merged
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
4 changes: 2 additions & 2 deletions crates/uv-distribution-types/src/prioritized_distribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ fn implied_python_markers(filename: &WheelFilename) -> MarkerTree {
// No Python tag means no Python version requirement.
return MarkerTree::TRUE;
}
LanguageTag::Python { major, minor: None } => {
LanguageTag::Python { major, minor: None } | LanguageTag::CPythonMajor { major } => {
MarkerTree::expression(MarkerExpression::Version {
key: uv_pep508::MarkerValueVersion::PythonVersion,
specifier: VersionSpecifier::equals_star_version(Version::new([u64::from(
Expand Down Expand Up @@ -970,7 +970,7 @@ fn implied_python_markers(filename: &WheelFilename) -> MarkerTree {
LanguageTag::None | LanguageTag::Python { .. } => {
// No implementation marker needed
}
LanguageTag::CPython { .. } => {
LanguageTag::CPython { .. } | LanguageTag::CPythonMajor { .. } => {
tree.and(MarkerTree::expression(MarkerExpression::String {
key: MarkerValueString::PlatformPythonImplementation,
operator: MarkerOperator::Equal,
Expand Down
45 changes: 40 additions & 5 deletions crates/uv-platform-tags/src/language_tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ pub enum LanguageTag {
GraalPy { python_version: (u8, u8) },
/// Ex) `pyston38`
Pyston { python_version: (u8, u8) },
/// Ex) `cp3`, specifically in `cp3-none-any`
CPythonMajor { major: u8 },
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BurntSushi Is that a forward-compatible change with rkyv?

Copy link
Member

@BurntSushi BurntSushi Dec 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know off the top of my head, but the docs suggest it isn't in the sense that "any change is possibly breaking." There isn't much more about it in the book.

I don't know enough about rkyv internals to know whether this is actually breaking or not. I can imagine both worlds. e.g., A scheme based on knowing there are N total variants may not be compatible with something when there are N+1 variants. Particularly if N+1 causes the size of the tag used by the enum to increase.

}

impl LanguageTag {
Expand All @@ -58,6 +60,7 @@ impl LanguageTag {
Self::Pyston {
python_version: (major, minor),
} => Some(format!("Pyston {major}.{minor}")),
Self::CPythonMajor { major } => Some(format!("CPython {major}")),
}
}
}
Expand Down Expand Up @@ -94,6 +97,9 @@ impl std::fmt::Display for LanguageTag {
} => {
write!(f, "pyston{major}{minor}")
}
Self::CPythonMajor { major } => {
write!(f, "cp{major}")
}
}
}
}
Expand Down Expand Up @@ -181,11 +187,36 @@ impl FromStr for LanguageTag {
}
}
} else if let Some(cp) = s.strip_prefix("cp") {
// Ex) `cp39`
let (major, minor) = parse_python_version(cp, "CPython", s)?;
Ok(Self::CPython {
python_version: (major, minor),
})
match cp.len() {
0 => Err(ParseLanguageTagError::MissingMajorVersion {
implementation: "CPython",
tag: s.to_string(),
}),
1 => {
// Ex) `cp3`
let major = cp
.chars()
.next()
.ok_or_else(|| ParseLanguageTagError::MissingMajorVersion {
implementation: "CPython",
tag: s.to_string(),
})?
.to_digit(10)
.ok_or_else(|| ParseLanguageTagError::InvalidMajorVersion {
implementation: "CPython",
tag: s.to_string(),
})? as u8;
Ok(Self::CPythonMajor { major })
}
2 | 3 => {
// Ex) `cp39`, `cp310`
let (major, minor) = parse_python_version(cp, "CPython", s)?;
Ok(Self::CPython {
python_version: (major, minor),
})
}
_ => Err(ParseLanguageTagError::UnknownFormat(s.to_string())),
}
} else if let Some(pp) = s.strip_prefix("pp") {
// Ex) `pp39`
let (major, minor) = parse_python_version(pp, "PyPy", s)?;
Expand Down Expand Up @@ -290,6 +321,10 @@ mod tests {
assert_eq!(LanguageTag::from_str("cp39"), Ok(tag));
assert_eq!(tag.to_string(), "cp39");

let tag = LanguageTag::CPythonMajor { major: 3 };
assert_eq!(LanguageTag::from_str("cp3"), Ok(tag));
assert_eq!(tag.to_string(), "cp3");

assert_eq!(
LanguageTag::from_str("cp"),
Err(ParseLanguageTagError::MissingMajorVersion {
Expand Down
Loading