@@ -3,8 +3,10 @@ use std::io::{BufReader, Read};
33use std:: path:: Path ;
44use std:: str:: FromStr ;
55
6+ #[ cfg( feature = "bzip2" ) ]
67use bzip2:: read:: BzDecoder ;
78use flate2:: read:: GzDecoder ;
9+ #[ cfg( feature = "xz" ) ]
810use xz:: read:: XzDecoder ;
911use zip:: ZipArchive ;
1012
@@ -24,9 +26,12 @@ pub enum DistributionType {
2426#[ derive( Debug , Clone , Copy ) ]
2527enum 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 }
0 commit comments