Skip to content

Commit

Permalink
Include pre-release Python versions in uv python list (#7290)
Browse files Browse the repository at this point in the history
Follows #7278

Closes #7280

`uv python list` should show installed pre-release versions, even though
we don't select them by default (as defined by #7300 and
#7278)
  • Loading branch information
zanieb authored Sep 11, 2024
1 parent ebd73d8 commit c50eb12
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
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

0 comments on commit c50eb12

Please sign in to comment.