Skip to content

Commit 05aab12

Browse files
committed
Remove xz entirely
Signed-off-by: William Woodruff <william@astral.sh>
1 parent a38cfe0 commit 05aab12

24 files changed

Lines changed: 471 additions & 215 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ async-channel = { version = "2.3.1" }
100100
async-compression = { version = "0.4.12", features = [
101101
"bzip2",
102102
"gzip",
103-
"xz",
104103
"zstd",
105104
] }
106105
async-trait = { version = "0.1.82" }
@@ -301,7 +300,6 @@ windows-registry = { version = "0.5.0" }
301300
windows-version = { version = "0.1.6" }
302301
wiremock = { version = "0.6.4" }
303302
wmi = { version = "0.18.3", default-features = false }
304-
xz2 = { version = "0.1.7", features = ["static"] }
305303
zeroize = { version = "1.8.1" }
306304
zip = { version = "8.1.0", default-features = false, features = [
307305
"deflate",

crates/uv-bench/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,3 @@ tokio = { workspace = true }
4949

5050
[package.metadata.cargo-shear]
5151
ignored = ["uv-extract"]
52-
53-
[features]
54-
static = ["uv-extract/static"]

crates/uv-bin-install/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use tokio::io::{AsyncRead, ReadBuf};
2121
use tokio_util::compat::FuturesAsyncReadCompatExt;
2222
use url::Url;
2323
use uv_client::retryable_on_request_failure;
24+
use uv_distribution_filename::LegacySourceDistExtension;
2425
use uv_distribution_filename::SourceDistExtension;
2526

2627
use uv_cache::{Cache, CacheBucket, CacheEntry, Error as CacheError};
@@ -170,7 +171,7 @@ impl ArchiveFormat {
170171
impl From<ArchiveFormat> for SourceDistExtension {
171172
fn from(val: ArchiveFormat) -> Self {
172173
match val {
173-
ArchiveFormat::Zip => Self::Zip,
174+
ArchiveFormat::Zip => Self::Legacy(LegacySourceDistExtension::Zip),
174175
ArchiveFormat::TarGz => Self::TarGz,
175176
}
176177
}

crates/uv-dev/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ name = "uv-dev"
7272
required-features = ["dev"]
7373

7474
[features]
75-
default = ["performance", "uv-extract/static"]
75+
default = ["performance"]
7676
# Actually build the dev CLI.
7777
dev = []
7878
performance = ["performance-memory-allocator"]

crates/uv-distribution-filename/src/extension.rs

Lines changed: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,29 @@ pub enum DistExtension {
2727
)]
2828
#[rkyv(derive(Debug))]
2929
pub enum SourceDistExtension {
30+
TarGz,
31+
Legacy(LegacySourceDistExtension),
32+
}
33+
34+
#[derive(
35+
Clone,
36+
Copy,
37+
Debug,
38+
PartialEq,
39+
Eq,
40+
PartialOrd,
41+
Ord,
42+
Hash,
43+
Serialize,
44+
Deserialize,
45+
rkyv::Archive,
46+
rkyv::Deserialize,
47+
rkyv::Serialize,
48+
)]
49+
#[rkyv(derive(Debug))]
50+
pub enum LegacySourceDistExtension {
3051
Tar,
3152
TarBz2,
32-
TarGz,
3353
TarLz,
3454
TarLzma,
3555
TarXz,
@@ -83,41 +103,49 @@ impl SourceDistExtension {
83103

84104
match extension {
85105
"gz" if is_tar(path.as_ref()) => Ok(Self::TarGz),
86-
// TODO: Remove these other extensions in the future.
87-
// NOTE: These get parsed from network sources like PyPI, so we don't
88-
// necessarily want to hard-fail, just skip in the future.
89-
"zip" => Ok(Self::Zip),
90-
"tar" => Ok(Self::Tar),
91-
"tgz" => Ok(Self::Tgz),
92-
"tbz" => Ok(Self::Tbz),
93-
"txz" => Ok(Self::Txz),
94-
"tlz" => Ok(Self::Tlz),
95-
"bz2" if is_tar(path.as_ref()) => Ok(Self::TarBz2),
96-
"xz" if is_tar(path.as_ref()) => Ok(Self::TarXz),
97-
"lz" if is_tar(path.as_ref()) => Ok(Self::TarLz),
98-
"lzma" if is_tar(path.as_ref()) => Ok(Self::TarLzma),
99-
"zst" if is_tar(path.as_ref()) => Ok(Self::TarZst),
106+
"zip" => Ok(Self::Legacy(LegacySourceDistExtension::Zip)),
107+
"tar" => Ok(Self::Legacy(LegacySourceDistExtension::Tar)),
108+
"tgz" => Ok(Self::Legacy(LegacySourceDistExtension::Tgz)),
109+
"tbz" => Ok(Self::Legacy(LegacySourceDistExtension::Tbz)),
110+
"txz" => Ok(Self::Legacy(LegacySourceDistExtension::Txz)),
111+
"tlz" => Ok(Self::Legacy(LegacySourceDistExtension::Tlz)),
112+
"bz2" if is_tar(path.as_ref()) => Ok(Self::Legacy(LegacySourceDistExtension::TarBz2)),
113+
"xz" if is_tar(path.as_ref()) => Ok(Self::Legacy(LegacySourceDistExtension::TarXz)),
114+
"lz" if is_tar(path.as_ref()) => Ok(Self::Legacy(LegacySourceDistExtension::TarLz)),
115+
"lzma" if is_tar(path.as_ref()) => Ok(Self::Legacy(LegacySourceDistExtension::TarLzma)),
116+
"zst" if is_tar(path.as_ref()) => Ok(Self::Legacy(LegacySourceDistExtension::TarZst)),
100117
_ => Err(ExtensionError::SourceDist),
101118
}
102119
}
103120

104121
/// Return the name for the extension.
105122
pub fn name(&self) -> &'static str {
106123
match self {
107-
Self::Tar => "tar",
108-
Self::TarBz2 => "tar.bz2",
109124
Self::TarGz => "tar.gz",
110-
Self::TarLz => "tar.lz",
111-
Self::TarLzma => "tar.lzma",
112-
Self::TarXz => "tar.xz",
113-
Self::TarZst => "tar.zst",
114-
Self::Tbz => "tbz",
115-
Self::Tgz => "tgz",
116-
Self::Tlz => "tlz",
117-
Self::Txz => "txz",
118-
Self::Zip => "zip",
125+
Self::Legacy(LegacySourceDistExtension::Tar) => "tar",
126+
Self::Legacy(LegacySourceDistExtension::TarBz2) => "tar.bz2",
127+
Self::Legacy(LegacySourceDistExtension::TarLz) => "tar.lz",
128+
Self::Legacy(LegacySourceDistExtension::TarLzma) => "tar.lzma",
129+
Self::Legacy(LegacySourceDistExtension::TarXz) => "tar.xz",
130+
Self::Legacy(LegacySourceDistExtension::TarZst) => "tar.zst",
131+
Self::Legacy(LegacySourceDistExtension::Tbz) => "tbz",
132+
Self::Legacy(LegacySourceDistExtension::Tgz) => "tgz",
133+
Self::Legacy(LegacySourceDistExtension::Tlz) => "tlz",
134+
Self::Legacy(LegacySourceDistExtension::Txz) => "txz",
135+
Self::Legacy(LegacySourceDistExtension::Zip) => "zip",
119136
}
120137
}
138+
139+
/// Returns `true` if the extension conforms to [PEP 625](https://peps.python.org/pep-0625/)'s
140+
/// naming requirements.
141+
///
142+
/// PEP 625 mandates `.tar.gz`; `.zip` is also accepted for backwards compatibility.
143+
pub fn is_pep625_compliant(&self) -> bool {
144+
matches!(
145+
self,
146+
Self::TarGz | Self::Legacy(LegacySourceDistExtension::Zip)
147+
)
148+
}
121149
}
122150

123151
impl Display for SourceDistExtension {

crates/uv-distribution-filename/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ use uv_pep440::Version;
77
pub use build_tag::{BuildTag, BuildTagError};
88
pub use egg::{EggInfoFilename, EggInfoFilenameError};
99
pub use expanded_tags::{ExpandedTagError, ExpandedTags};
10-
pub use extension::{DistExtension, ExtensionError, SourceDistExtension};
10+
pub use extension::{
11+
DistExtension, ExtensionError, LegacySourceDistExtension, SourceDistExtension,
12+
};
1113
pub use source_dist::{SourceDistFilename, SourceDistFilenameError};
1214
pub use wheel::{WheelFilename, WheelFilenameError};
1315

crates/uv-distribution-filename/src/source_dist.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ mod tests {
177177

178178
use uv_normalize::PackageName;
179179

180-
use crate::{SourceDistExtension, SourceDistFilename};
180+
use crate::{SourceDistExtension, SourceDistFilename, extension::LegacySourceDistExtension};
181181

182182
/// Only test already normalized names since the parsing is lossy
183183
///
@@ -229,7 +229,7 @@ mod tests {
229229
assert!(
230230
SourceDistFilename::parse(
231231
"foo.zip",
232-
SourceDistExtension::Zip,
232+
SourceDistExtension::Legacy(LegacySourceDistExtension::Zip),
233233
&PackageName::from_str("foo-lib").unwrap()
234234
)
235235
.is_err()

crates/uv-distribution-types/src/error.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,9 @@ pub enum Error {
2020

2121
#[error("Requested package name `{0}` does not match `{1}` in the distribution filename: {2}")]
2222
PackageNameMismatch(PackageName, PackageName, String),
23+
24+
#[error(
25+
"Source distribution `{0}` has a non-PEP 625-compliant filename; only `.tar.gz` and `.zip` archives are accepted"
26+
)]
27+
NotPep625Filename(String),
2328
}

crates/uv-distribution-types/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,9 @@ impl Dist {
395395
})))
396396
}
397397
DistExtension::Source(ext) => {
398+
if !ext.is_pep625_compliant() {
399+
return Err(Error::NotPep625Filename(url.verbatim().to_string()));
400+
}
398401
Ok(Self::Source(SourceDist::DirectUrl(DirectUrlSourceDist {
399402
name,
400403
location: Box::new(location),
@@ -443,6 +446,10 @@ impl Dist {
443446
})))
444447
}
445448
DistExtension::Source(ext) => {
449+
if !ext.is_pep625_compliant() {
450+
return Err(Error::NotPep625Filename(url.verbatim().to_string()));
451+
}
452+
446453
// If there is a version in the filename, record it.
447454
let version = url
448455
.filename()

0 commit comments

Comments
 (0)