Skip to content

Commit

Permalink
Correct Pyston tag format (#10580)
Browse files Browse the repository at this point in the history
## Summary

Empirically, it looks like the format here is slightly different than
what we had in the code? Our integration test caught it.
  • Loading branch information
charliermarsh authored Jan 14, 2025
1 parent 5c91217 commit 3fd090b
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 80 deletions.
50 changes: 16 additions & 34 deletions crates/uv-platform-tags/src/abi_tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,8 @@ pub enum AbiTag {
python_version: (u8, u8),
implementation_version: (u8, u8),
},
/// Ex) `pyston38-pyston_23`
Pyston {
python_version: (u8, u8),
implementation_version: (u8, u8),
},
/// Ex) `pyston_23_x86_64_linux_gnu`
Pyston { implementation_version: (u8, u8) },
}

impl std::fmt::Display for AbiTag {
Expand Down Expand Up @@ -82,13 +79,9 @@ impl std::fmt::Display for AbiTag {
)
}
Self::Pyston {
python_version: (py_major, py_minor),
implementation_version: (impl_major, impl_minor),
} => {
write!(
f,
"pyston{py_major}{py_minor}-pyston_{impl_major}{impl_minor}"
)
write!(f, "pyston_{impl_major}{impl_minor}_x86_64_linux_gnu")
}
}
}
Expand Down Expand Up @@ -229,24 +222,21 @@ impl FromStr for AbiTag {
implementation_version: (impl_major, impl_minor),
})
} else if let Some(rest) = s.strip_prefix("pyston") {
// Ex) `pyston38-pyston_23`
let version_end = rest
.find('-')
// Ex) `pyston_23_x86_64_linux_gnu`
let rest = rest
.strip_prefix("_")
.ok_or_else(|| ParseAbiTagError::InvalidFormat {
implementation: "Pyston",
tag: s.to_string(),
})?;
let version_str = &rest[..version_end];
let (major, minor) = parse_python_version(version_str, "Pyston", s)?;
let rest = rest[version_end + 1..]
.strip_prefix("pyston_")
.ok_or_else(|| ParseAbiTagError::InvalidFormat {
let rest = rest.strip_suffix("_x86_64_linux_gnu").ok_or_else(|| {
ParseAbiTagError::InvalidFormat {
implementation: "Pyston",
tag: s.to_string(),
})?;
}
})?;
let (impl_major, impl_minor) = parse_impl_version(rest, "Pyston", s)?;
Ok(Self::Pyston {
python_version: (major, minor),
implementation_version: (impl_major, impl_minor),
})
} else {
Expand Down Expand Up @@ -426,31 +416,23 @@ mod tests {
#[test]
fn pyston_abi() {
let tag = AbiTag::Pyston {
python_version: (3, 8),
implementation_version: (2, 3),
};
assert_eq!(AbiTag::from_str("pyston38-pyston_23"), Ok(tag));
assert_eq!(tag.to_string(), "pyston38-pyston_23");
assert_eq!(AbiTag::from_str("pyston_23_x86_64_linux_gnu"), Ok(tag));
assert_eq!(tag.to_string(), "pyston_23_x86_64_linux_gnu");

assert_eq!(
AbiTag::from_str("pyston38"),
Err(ParseAbiTagError::InvalidFormat {
implementation: "Pyston",
tag: "pyston38".to_string()
})
);
assert_eq!(
AbiTag::from_str("pyston38_23"),
AbiTag::from_str("pyston23_x86_64_linux_gnu"),
Err(ParseAbiTagError::InvalidFormat {
implementation: "Pyston",
tag: "pyston38_23".to_string()
tag: "pyston23_x86_64_linux_gnu".to_string()
})
);
assert_eq!(
AbiTag::from_str("pyston38-pyston_XY"),
AbiTag::from_str("pyston_XY_x86_64_linux_gnu"),
Err(ParseAbiTagError::InvalidImplMajorVersion {
implementation: "Pyston",
tag: "pyston38-pyston_XY".to_string()
tag: "pyston_XY_x86_64_linux_gnu".to_string()
})
);
}
Expand Down
86 changes: 50 additions & 36 deletions crates/uv-platform-tags/src/language_tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub enum LanguageTag {
PyPy { python_version: (u8, u8) },
/// Ex) `graalpy310`
GraalPy { python_version: (u8, u8) },
/// Ex) `pt38`
/// Ex) `pyston38`
Pyston { python_version: (u8, u8) },
}

Expand Down Expand Up @@ -64,7 +64,7 @@ impl std::fmt::Display for LanguageTag {
Self::Pyston {
python_version: (major, minor),
} => {
write!(f, "pt{major}{minor}")
write!(f, "pyston{major}{minor}")
}
}
}
Expand Down Expand Up @@ -111,28 +111,48 @@ impl FromStr for LanguageTag {
if s == "none" {
Ok(Self::None)
} else if let Some(py) = s.strip_prefix("py") {
if py.len() == 1 {
// Ex) `py3`
let major = py
.chars()
.next()
.ok_or_else(|| ParseLanguageTagError::MissingMajorVersion {
match py.len() {
0 => {
return Err(ParseLanguageTagError::MissingMajorVersion {
implementation: "Python",
tag: s.to_string(),
})?
.to_digit(10)
.ok_or_else(|| ParseLanguageTagError::InvalidMajorVersion {
implementation: "Python",
tag: s.to_string(),
})? as u8;
Ok(Self::Python { major, minor: None })
} else {
// Ex) `py39`
let (major, minor) = parse_python_version(py, "Python", s)?;
Ok(Self::Python {
major,
minor: Some(minor),
})
});
}
1 => {
// Ex) `py3`
let major = py
.chars()
.next()
.ok_or_else(|| ParseLanguageTagError::MissingMajorVersion {
implementation: "Python",
tag: s.to_string(),
})?
.to_digit(10)
.ok_or_else(|| ParseLanguageTagError::InvalidMajorVersion {
implementation: "Python",
tag: s.to_string(),
})? as u8;
Ok(Self::Python { major, minor: None })
}
2 | 3 => {
// Ex) `py39`, `py310`
let (major, minor) = parse_python_version(py, "Python", s)?;
Ok(Self::Python {
major,
minor: Some(minor),
})
}
_ => {
if let Some(pyston) = py.strip_prefix("ston") {
// Ex) `pyston38`
let (major, minor) = parse_python_version(pyston, "Pyston", s)?;
Ok(Self::Pyston {
python_version: (major, minor),
})
} else {
Err(ParseLanguageTagError::UnknownFormat(s.to_string()))
}
}
}
} else if let Some(cp) = s.strip_prefix("cp") {
// Ex) `cp39`
Expand All @@ -152,12 +172,6 @@ impl FromStr for LanguageTag {
Ok(Self::GraalPy {
python_version: (major, minor),
})
} else if let Some(pt) = s.strip_prefix("pt") {
// Ex) `pt38`
let (major, minor) = parse_python_version(pt, "Pyston", s)?;
Ok(Self::Pyston {
python_version: (major, minor),
})
} else {
Err(ParseLanguageTagError::UnknownFormat(s.to_string()))
}
Expand Down Expand Up @@ -340,28 +354,28 @@ mod tests {
let tag = LanguageTag::Pyston {
python_version: (3, 8),
};
assert_eq!(LanguageTag::from_str("pt38"), Ok(tag));
assert_eq!(tag.to_string(), "pt38");
assert_eq!(LanguageTag::from_str("pyston38"), Ok(tag));
assert_eq!(tag.to_string(), "pyston38");

assert_eq!(
LanguageTag::from_str("pt"),
LanguageTag::from_str("pyston"),
Err(ParseLanguageTagError::MissingMajorVersion {
implementation: "Pyston",
tag: "pt".to_string()
tag: "pyston".to_string()
})
);
assert_eq!(
LanguageTag::from_str("ptX"),
LanguageTag::from_str("pystonX"),
Err(ParseLanguageTagError::InvalidMajorVersion {
implementation: "Pyston",
tag: "ptX".to_string()
tag: "pystonX".to_string()
})
);
assert_eq!(
LanguageTag::from_str("pt3X"),
LanguageTag::from_str("pyston3X"),
Err(ParseLanguageTagError::InvalidMinorVersion {
implementation: "Pyston",
tag: "pt3X".to_string()
tag: "pyston3X".to_string()
})
);
}
Expand Down
5 changes: 2 additions & 3 deletions crates/uv-platform-tags/src/tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ impl Implementation {
Self::PyPy => LanguageTag::PyPy { python_version },
// Ex) `graalpy310`
Self::GraalPy => LanguageTag::GraalPy { python_version },
// Ex) `pt38``
// Ex) `pyston38`
Self::Pyston => LanguageTag::Pyston { python_version },
}
}
Expand All @@ -398,9 +398,8 @@ impl Implementation {
python_version,
implementation_version,
},
// Ex) `pyston38-pyston_23`
// Ex) `pyston_23_x86_64_linux`
Self::Pyston => AbiTag::Pyston {
python_version,
implementation_version,
},
}
Expand Down
7 changes: 0 additions & 7 deletions crates/uv-resolver/src/requires_python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,6 @@ impl RequiresPython {
} | AbiTag::GraalPy {
python_version: (2, ..),
..
} | AbiTag::Pyston {
python_version: (2, ..),
..
}
) {
// Python 2 is never allowed.
Expand All @@ -487,10 +484,6 @@ impl RequiresPython {
| AbiTag::GraalPy {
python_version: (3, minor),
..
}
| AbiTag::Pyston {
python_version: (3, minor),
..
} = abi_tag
{
// Ex) If the wheel bound is `3.6`, then it doesn't match `>=3.10`.
Expand Down

0 comments on commit 3fd090b

Please sign in to comment.