mirror of
https://github.com/astral-sh/uv.git
synced 2025-11-02 04:48:18 +00:00
Correct Pyston tag format (#10580)
## Summary Empirically, it looks like the format here is slightly different than what we had in the code? Our integration test caught it.
This commit is contained in:
parent
5c91217488
commit
3fd090b373
4 changed files with 68 additions and 80 deletions
|
|
@ -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 {
|
||||
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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 {
|
||||
|
|
@ -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"),
|
||||
AbiTag::from_str("pyston23_x86_64_linux_gnu"),
|
||||
Err(ParseAbiTagError::InvalidFormat {
|
||||
implementation: "Pyston",
|
||||
tag: "pyston38".to_string()
|
||||
tag: "pyston23_x86_64_linux_gnu".to_string()
|
||||
})
|
||||
);
|
||||
assert_eq!(
|
||||
AbiTag::from_str("pyston38_23"),
|
||||
Err(ParseAbiTagError::InvalidFormat {
|
||||
implementation: "Pyston",
|
||||
tag: "pyston38_23".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()
|
||||
})
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) },
|
||||
}
|
||||
|
||||
|
|
@ -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}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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`
|
||||
|
|
@ -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()))
|
||||
}
|
||||
|
|
@ -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()
|
||||
})
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 },
|
||||
}
|
||||
}
|
||||
|
|
@ -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,
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -469,9 +469,6 @@ impl RequiresPython {
|
|||
} | AbiTag::GraalPy {
|
||||
python_version: (2, ..),
|
||||
..
|
||||
} | AbiTag::Pyston {
|
||||
python_version: (2, ..),
|
||||
..
|
||||
}
|
||||
) {
|
||||
// Python 2 is never allowed.
|
||||
|
|
@ -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`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue