Add support for any Python requests (#4948)

For roundtrip in #4949 — it should also be fine to request `any` but the
user can't construct it right now.
This commit is contained in:
Zanie Blue 2024-07-10 11:20:06 -04:00 committed by GitHub
parent aa8f126f13
commit 3d1ab81c28
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -974,6 +974,11 @@ impl PythonRequest {
/// ///
/// This cannot fail, which means weird inputs will be parsed as [`PythonRequest::File`] or [`PythonRequest::ExecutableName`]. /// This cannot fail, which means weird inputs will be parsed as [`PythonRequest::File`] or [`PythonRequest::ExecutableName`].
pub fn parse(value: &str) -> Self { pub fn parse(value: &str) -> Self {
// e.g. `any`
if value.eq_ignore_ascii_case("any") {
return Self::Any;
}
// e.g. `3.12.1`, `312`, or `>=3.12` // e.g. `3.12.1`, `312`, or `>=3.12`
if let Ok(version) = VersionRequest::from_str(value) { if let Ok(version) = VersionRequest::from_str(value) {
return Self::Version(version); return Self::Version(version);
@ -1581,6 +1586,7 @@ mod tests {
#[test] #[test]
fn interpreter_request_from_str() { fn interpreter_request_from_str() {
assert_eq!(PythonRequest::parse("any"), PythonRequest::Any);
assert_eq!( assert_eq!(
PythonRequest::parse("3.12"), PythonRequest::parse("3.12"),
PythonRequest::Version(VersionRequest::from_str("3.12").unwrap()) PythonRequest::Version(VersionRequest::from_str("3.12").unwrap())