Add support for .tar.bz2 source distributions (#3069)

## Summary

Source distributions in the .tar.bz2 format are still relatively common
within the existing code-bases, namely, the most common examples are the
Twisted source distributions up to the version 20.3.0. As quite so often
the ability to upgrade Twisted to a more recent version is not available
for a given project, we add the support for .tar.bz2 here to still allow
`uv` to be a drop-in replacement for `pip` in these projects.

## Test Plan

The feature was tested both by adding the corresponding test coverage,
and by directly installing a package of interest under a Python version
that doesn't have the corresponding wheel:

```sh
cargo run venv -p python3.8
cargo run pip install Twisted==20.3.0 --no-cache
```

The `--no-cache` argument in the example above serves the purpose of
cleaning the cached information regarding the unsatisfiability of the
requirements, as it may have been cached during some previous attempt to
install this package by `uv` version that didn't implement this feature
yet.
This commit is contained in:
Sergey Kolosov 2024-04-16 21:34:55 +03:00 committed by GitHub
parent e78bbb8f6a
commit d2551bb2bd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 115 additions and 4 deletions

View file

@ -19,6 +19,7 @@ use uv_normalize::{InvalidNameError, PackageName};
pub enum SourceDistExtension {
Zip,
TarGz,
TarBz2,
}
impl FromStr for SourceDistExtension {
@ -28,6 +29,7 @@ impl FromStr for SourceDistExtension {
Ok(match s {
"zip" => Self::Zip,
"tar.gz" => Self::TarGz,
"tar.bz2" => Self::TarBz2,
other => return Err(other.to_string()),
})
}
@ -38,6 +40,7 @@ impl Display for SourceDistExtension {
match self {
Self::Zip => f.write_str("zip"),
Self::TarGz => f.write_str("tar.gz"),
Self::TarBz2 => f.write_str("tar.bz2"),
}
}
}
@ -50,6 +53,9 @@ impl SourceDistExtension {
if let Some(stem) = filename.strip_suffix(".tar.gz") {
return Some((stem, Self::TarGz));
}
if let Some(stem) = filename.strip_suffix(".tar.bz2") {
return Some((stem, Self::TarBz2));
}
None
}
}
@ -182,7 +188,7 @@ impl Display for SourceDistFilenameError {
enum SourceDistFilenameErrorKind {
#[error("Name doesn't start with package name {0}")]
Filename(PackageName),
#[error("Source distributions filenames must end with .zip or .tar.gz")]
#[error("Source distributions filenames must end with .zip, .tar.gz, or .tar.bz2")]
Extension,
#[error("Version section is invalid")]
Version(#[from] VersionParseError),
@ -207,6 +213,7 @@ mod tests {
"foo-lib-1.2.3.zip",
"foo-lib-1.2.3a3.zip",
"foo-lib-1.2.3.tar.gz",
"foo-lib-1.2.3.tar.bz2",
] {
assert_eq!(
SourceDistFilename::parse(normalized, &PackageName::from_str("foo_lib").unwrap())