@@ -31,6 +31,7 @@ enum SDistType {
3131pub struct Distribution {
3232 dist_type : DistributionType ,
3333 metadata : Metadata ,
34+ python_version : String ,
3435}
3536
3637impl FromStr for SDistType {
@@ -58,17 +59,44 @@ impl Distribution {
5859 "whl" => DistributionType :: Wheel ,
5960 _ => return Err ( Error :: UnknownDistributionType ) ,
6061 } ;
61- let metadata = match dist_type {
62+ let ( metadata, python_version ) = match dist_type {
6263 DistributionType :: SDist => {
6364 let sdist_type: SDistType = ext. parse ( ) ?;
64- Self :: parse_sdist ( path, sdist_type)
65+ ( Self :: parse_sdist ( path, sdist_type) ? , "source" . to_string ( ) )
6566 }
66- DistributionType :: Egg => Self :: parse_egg ( path) ,
67- DistributionType :: Wheel => Self :: parse_wheel ( path) ,
68- } ?;
67+ DistributionType :: Egg => {
68+ let parts: Vec < & str > = path
69+ . file_stem ( )
70+ . unwrap ( )
71+ . to_str ( )
72+ . unwrap ( )
73+ . split ( '-' )
74+ . collect ( ) ;
75+ let python_version = match parts. as_slice ( ) {
76+ [ _name, _version, py_ver] => py_ver,
77+ _ => "any" ,
78+ } ;
79+ ( Self :: parse_egg ( path) ?, python_version. to_string ( ) )
80+ }
81+ DistributionType :: Wheel => {
82+ let parts: Vec < & str > = path
83+ . file_stem ( )
84+ . unwrap ( )
85+ . to_str ( )
86+ . unwrap ( )
87+ . split ( '-' )
88+ . collect ( ) ;
89+ let python_version = match parts. as_slice ( ) {
90+ [ _name, _version, py_ver, _abi_tag, _plat_tag] => py_ver,
91+ _ => "any" ,
92+ } ;
93+ ( Self :: parse_wheel ( path) ?, python_version. to_string ( ) )
94+ }
95+ } ;
6996 return Ok ( Self {
7097 dist_type,
7198 metadata,
99+ python_version,
72100 } ) ;
73101 }
74102 Err ( Error :: UnknownDistributionType )
@@ -84,6 +112,13 @@ impl Distribution {
84112 & self . metadata
85113 }
86114
115+ /// Returns the supported Python version tag
116+ ///
117+ /// For source distributions the version tag is always `source`
118+ pub fn python_version ( & self ) -> & str {
119+ & self . python_version
120+ }
121+
87122 fn parse_sdist ( path : & Path , sdist_type : SDistType ) -> Result < Metadata , Error > {
88123 match sdist_type {
89124 SDistType :: Zip => Self :: parse_zip ( path, "PKG-INFO" ) ,
0 commit comments