@@ -76,25 +76,20 @@ impl Distribution {
76
76
/// Open and parse a distribution from `path`
77
77
pub fn new ( path : impl AsRef < Path > ) -> Result < Self , Error > {
78
78
let path = path. as_ref ( ) ;
79
- if let Some ( ext) = path. extension ( ) . and_then ( |ext| ext. to_str ( ) ) {
80
- let dist_type = match ext {
81
- "zip" | "gz" => DistributionType :: SDist ,
82
- "egg" => DistributionType :: Egg ,
83
- "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 ,
90
- _ => return Err ( Error :: UnknownDistributionType ) ,
91
- } ;
92
- let ( metadata, python_version) = match dist_type {
93
- DistributionType :: SDist => {
94
- let sdist_type: SDistType = ext. parse ( ) ?;
95
- ( Self :: parse_sdist ( path, sdist_type) ?, "source" . to_string ( ) )
96
- }
97
- DistributionType :: Egg => {
79
+ let ext = path
80
+ . extension ( )
81
+ . and_then ( |ext| ext. to_str ( ) )
82
+ . ok_or ( Error :: UnknownDistributionType ) ?;
83
+
84
+ Ok ( if let Ok ( sdist_type) = ext. parse ( ) {
85
+ Self {
86
+ dist_type : DistributionType :: SDist ,
87
+ metadata : Self :: parse_sdist ( path, sdist_type) ?,
88
+ python_version : "source" . to_string ( ) ,
89
+ }
90
+ } else {
91
+ match ext {
92
+ "egg" => {
98
93
let parts: Vec < & str > = path
99
94
. file_stem ( )
100
95
. unwrap ( )
@@ -106,9 +101,13 @@ impl Distribution {
106
101
[ _name, _version, py_ver] => py_ver,
107
102
_ => "any" ,
108
103
} ;
109
- ( Self :: parse_egg ( path) ?, python_version. to_string ( ) )
104
+ Self {
105
+ dist_type : DistributionType :: Egg ,
106
+ metadata : Self :: parse_egg ( path) ?,
107
+ python_version : python_version. to_string ( ) ,
108
+ }
110
109
}
111
- DistributionType :: Wheel => {
110
+ "whl" => {
112
111
let parts: Vec < & str > = path
113
112
. file_stem ( )
114
113
. unwrap ( )
@@ -120,16 +119,15 @@ impl Distribution {
120
119
[ _name, _version, py_ver, _abi_tag, _plat_tag] => py_ver,
121
120
_ => "any" ,
122
121
} ;
123
- ( Self :: parse_wheel ( path) ?, python_version. to_string ( ) )
122
+ Self {
123
+ dist_type : DistributionType :: Wheel ,
124
+ metadata : Self :: parse_wheel ( path) ?,
125
+ python_version : python_version. to_string ( ) ,
126
+ }
124
127
}
125
- } ;
126
- return Ok ( Self {
127
- dist_type,
128
- metadata,
129
- python_version,
130
- } ) ;
131
- }
132
- Err ( Error :: UnknownDistributionType )
128
+ _ => return Err ( Error :: UnknownDistributionType ) ,
129
+ }
130
+ } )
133
131
}
134
132
135
133
/// Returns distribution type
0 commit comments