Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include pre-release Python versions in uv python list #7290

Merged
merged 1 commit into from
Sep 11, 2024
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
29 changes: 22 additions & 7 deletions crates/uv-python/src/downloads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ pub struct PythonDownloadRequest {
arch: Option<Arch>,
os: Option<Os>,
libc: Option<Libc>,

/// Whether to allow pre-releases or not. If not set, defaults to true if [`Self::version`] is
/// not None, and false otherwise.
prereleases: Option<bool>,
}

impl PythonDownloadRequest {
Expand All @@ -105,13 +109,15 @@ impl PythonDownloadRequest {
arch: Option<Arch>,
os: Option<Os>,
libc: Option<Libc>,
prereleases: Option<bool>,
) -> Self {
Self {
version,
implementation,
arch,
os,
libc,
prereleases,
}
}

Expand Down Expand Up @@ -145,6 +151,12 @@ impl PythonDownloadRequest {
self
}

#[must_use]
pub fn with_prereleases(mut self, prereleases: bool) -> Self {
self.prereleases = Some(prereleases);
self
}

/// Construct a new [`PythonDownloadRequest`] from a [`PythonRequest`] if possible.
///
/// Returns [`None`] if the request kind is not compatible with a download, e.g., it is
Expand Down Expand Up @@ -196,6 +208,7 @@ impl PythonDownloadRequest {
Some(Arch::from_env()),
Some(Os::from_env()),
Some(Libc::from_env()?),
None,
))
}

Expand Down Expand Up @@ -252,20 +265,22 @@ impl PythonDownloadRequest {
return false;
}
}
// If we don't allow pre-releases, don't match a key with a pre-release tag
if !self.allows_prereleases() && !key.prerelease.is_empty() {
return false;
}
true
}

/// Whether this request is satisfied by a Python download.
///
/// Note that unlike [`Self::satisfied_by_key`], this method will not match a pre-release
/// unless a version is included in the request.
pub fn satisfied_by_download(&self, download: &ManagedPythonDownload) -> bool {
if self.version.is_none() && !download.key().prerelease.is_empty() {
return false;
}
self.satisfied_by_key(download.key())
}

pub fn allows_prereleases(&self) -> bool {
self.prereleases.unwrap_or_else(|| self.version.is_some())
}

pub fn satisfied_by_interpreter(&self, interpreter: &Interpreter) -> bool {
if let Some(version) = self.version() {
if !version.matches_interpreter(interpreter) {
Expand Down Expand Up @@ -375,7 +390,7 @@ impl FromStr for PythonDownloadRequest {

return Err(Error::TooManyParts(s.to_string()));
}
Ok(Self::new(version, implementation, arch, os, libc))
Ok(Self::new(version, implementation, arch, os, libc, None))
}
}

Expand Down
4 changes: 3 additions & 1 deletion crates/uv/src/commands/python/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ pub(crate) async fn list(
None
}
}
};
}
// Include pre-release versions
.map(|request| request.with_prereleases(true));

let downloads = download_request
.as_ref()
Expand Down
2 changes: 2 additions & 0 deletions crates/uv/src/commands/python/uninstall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ async fn do_uninstall(
anyhow::anyhow!("Cannot uninstall managed Python for request: {request}")
})
})
// Always include pre-releases in uninstalls
.map(|result| result.map(|request| request.with_prereleases(true)))
.collect::<Result<Vec<_>>>()?;

let installed_installations: Vec<_> = installations.find_all()?.collect();
Expand Down
Loading