Skip to content

Commit 6703a29

Browse files
authored
Move .tar, .tar.bz2 and .tar.xz behind a off-by-default deprecated-formats feature flag
1 parent 798529c commit 6703a29

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ repository = "https://github.com/messense/python-pkginfo-rs"
1212
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1313

1414
[dependencies]
15-
bzip2 = "0.4.2"
15+
bzip2 = { version = "0.4.2", optional = true }
1616
flate2 = "1.0.20"
1717
fs-err = "2.6.0"
1818
mailparse = "0.13.4"
1919
serde = { version = "1.0.126", features = ["derive"], optional = true }
2020
tar = "0.4.35"
21-
xz = "0.1.0"
21+
xz = { version = "0.1.0", optional = true }
2222
zip = "0.5.12"
23+
24+
[features]
25+
deprecated-formats = ["bzip2", "xz"]

src/distribution.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ use std::io::{BufReader, Read};
33
use std::path::Path;
44
use std::str::FromStr;
55

6+
#[cfg(feature = "bzip2")]
67
use bzip2::read::BzDecoder;
78
use flate2::read::GzDecoder;
9+
#[cfg(feature = "xz")]
810
use xz::read::XzDecoder;
911
use zip::ZipArchive;
1012

@@ -24,9 +26,12 @@ pub enum DistributionType {
2426
#[derive(Debug, Clone, Copy)]
2527
enum SDistType {
2628
Zip,
27-
Tar,
2829
GzTar,
30+
#[cfg(feature = "deprecated-formats")]
31+
Tar,
32+
#[cfg(feature = "bzip2")]
2933
BzTar,
34+
#[cfg(feature = "xz")]
3035
XzTar,
3136
}
3237

@@ -54,9 +59,12 @@ impl FromStr for SDistType {
5459
fn from_str(s: &str) -> Result<Self, Self::Err> {
5560
let dist_type = match s {
5661
"zip" => SDistType::Zip,
57-
"tar" => SDistType::Tar,
5862
"gz" => SDistType::GzTar,
63+
#[cfg(feature = "deprecated-formats")]
64+
"tar" => SDistType::Tar,
65+
#[cfg(feature = "bzip2")]
5966
"bz2" => SDistType::BzTar,
67+
#[cfg(feature = "xz")]
6068
"xz" => SDistType::XzTar,
6169
_ => return Err(Error::UnknownDistributionType),
6270
};
@@ -70,9 +78,15 @@ impl Distribution {
7078
let path = path.as_ref();
7179
if let Some(ext) = path.extension().and_then(|ext| ext.to_str()) {
7280
let dist_type = match ext {
73-
"zip" | "tar" | "gz" | "bz2" | "xz" => DistributionType::SDist,
81+
"zip" | "gz" => DistributionType::SDist,
7482
"egg" => DistributionType::Egg,
7583
"whl" => DistributionType::Wheel,
84+
#[cfg(feature = "deprecated-formats")]
85+
"tar" => DistributionType::SDist,
86+
#[cfg(feature = "bzip2")]
87+
"bz2" => DistributionType::SDist,
88+
#[cfg(feature = "xz")]
89+
"xz" => DistributionType::SDist,
7690
_ => return Err(Error::UnknownDistributionType),
7791
};
7892
let (metadata, python_version) = match dist_type {
@@ -141,10 +155,13 @@ impl Distribution {
141155
SDistType::GzTar => {
142156
Self::parse_tar(GzDecoder::new(BufReader::new(fs_err::File::open(path)?)))
143157
}
158+
#[cfg(feature = "deprecated-formats")]
144159
SDistType::Tar => Self::parse_tar(BufReader::new(fs_err::File::open(path)?)),
160+
#[cfg(feature = "bzip2")]
145161
SDistType::BzTar => {
146162
Self::parse_tar(BzDecoder::new(BufReader::new(fs_err::File::open(path)?)))
147163
}
164+
#[cfg(feature = "xz")]
148165
SDistType::XzTar => {
149166
Self::parse_tar(XzDecoder::new(BufReader::new(fs_err::File::open(path)?)))
150167
}

tests/test_distribution.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ fn test_parse_sdist_zip() {
3636
assert_eq!(dist.python_version(), "source");
3737
}
3838

39+
#[cfg(feature = "deprecated-formats")]
3940
#[test]
4041
fn test_parse_sdist_tar() {
4142
let dist = Distribution::new("tests/fixtures/build-0.4.0.tar").unwrap();
@@ -59,6 +60,7 @@ fn test_parse_sdist_tar_gz() {
5960
assert_eq!(dist.python_version(), "source");
6061
}
6162

63+
#[cfg(feature = "bzip2")]
6264
#[test]
6365
fn test_parse_sdist_tar_bz2() {
6466
let dist = Distribution::new("tests/fixtures/build-0.4.0.tar.bz2").unwrap();
@@ -71,6 +73,7 @@ fn test_parse_sdist_tar_bz2() {
7173
assert_eq!(dist.python_version(), "source");
7274
}
7375

76+
#[cfg(feature = "xz")]
7477
#[test]
7578
fn test_parse_sdist_tar_xz() {
7679
let dist = Distribution::new("tests/fixtures/build-0.4.0.tar.xz").unwrap();

0 commit comments

Comments
 (0)