fix: Correctly parse wheel filename with build tags

This commit is contained in:
Denis Bilenko (aider) 2025-03-04 17:45:02 +01:00 committed by Denis Bilenko
parent 3135f4e38f
commit 5a60b73ad8
1 changed files with 12 additions and 6 deletions

View File

@ -33,7 +33,7 @@ func CalculateNewVersion(info *WheelInfo, mtime time.Time) (newVersion, newFilen
} }
// ParseWheelFilename parses a wheel filename and extracts its components. // ParseWheelFilename parses a wheel filename and extracts its components.
// Wheel filenames follow the pattern: {distribution}-{version}-{python_tag}-{abi_tag}-{platform_tag}.whl // Wheel filenames follow the pattern: {distribution}-{version}(-{build tag})?-{python_tag}-{abi_tag}-{platform_tag}.whl
func ParseWheelFilename(filename string) (*WheelInfo, error) { func ParseWheelFilename(filename string) (*WheelInfo, error) {
parts := strings.Split(filename, "-") parts := strings.Split(filename, "-")
if len(parts) < 5 { if len(parts) < 5 {
@ -48,12 +48,18 @@ func ParseWheelFilename(filename string) (*WheelInfo, error) {
tags := parts[tagStartIdx:] tags := parts[tagStartIdx:]
tags[2] = strings.TrimSuffix(tags[2], ".whl") tags[2] = strings.TrimSuffix(tags[2], ".whl")
// Everything before the tags except the version is the distribution // The version is the second part
versionIdx := tagStartIdx - 1 version := parts[1]
// If there are build tags, they are between the version and the python tag
// Include them in the version
if tagStartIdx > 2 {
buildTags := parts[2:tagStartIdx]
version = version + "-" + strings.Join(buildTags, "-")
}
// Distribution may contain hyphens, so join all parts before the version // The distribution is always the first part
distribution := strings.Join(parts[:versionIdx], "-") distribution := parts[0]
version := parts[versionIdx]
return &WheelInfo{ return &WheelInfo{
Distribution: distribution, Distribution: distribution,