Allow version specifiers to be used in Python version requests (#4214)

In service of https://github.com/astral-sh/uv/issues/4212 but this is
user-facing e.g. Python discovery will support version specifiers
everywhere now.

Closes https://github.com/astral-sh/uv/issues/4212
This commit is contained in:
Zanie Blue 2024-06-10 19:20:09 -04:00 committed by GitHub
parent 10e0abc9b1
commit 5f37395f45
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 119 additions and 61 deletions

View file

@ -1,6 +1,5 @@
use std::fmt::Display;
use std::io;
use std::num::ParseIntError;
use std::path::{Path, PathBuf};
use std::str::FromStr;
@ -26,7 +25,7 @@ pub enum Error {
#[error(transparent)]
ImplementationError(#[from] ImplementationError),
#[error("Invalid python version: {0}")]
InvalidPythonVersion(ParseIntError),
InvalidPythonVersion(String),
#[error("Download failed")]
NetworkError(#[from] BetterReqwestError),
#[error("Download failed")]
@ -215,7 +214,7 @@ impl PythonDownloadRequest {
impl Display for PythonDownloadRequest {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut parts = Vec::new();
if let Some(version) = self.version {
if let Some(version) = &self.version {
parts.push(version.to_string());
}
if let Some(implementation) = self.implementation {
@ -239,7 +238,8 @@ impl FromStr for PythonDownloadRequest {
fn from_str(s: &str) -> Result<Self, Self::Err> {
// TODO(zanieb): Implement parsing of additional request parts
let version = VersionRequest::from_str(s).map_err(Error::InvalidPythonVersion)?;
let version =
VersionRequest::from_str(s).map_err(|_| Error::InvalidPythonVersion(s.to_string()))?;
Ok(Self::new(Some(version), None, None, None, None))
}
}