From d79e0db71b2d8cb12d15d4854751960cc81d38de Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Wed, 5 Mar 2025 11:50:09 +0100 Subject: [PATCH] use cutSuffix; add link to pep --- libs/patchwheel/parse.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libs/patchwheel/parse.go b/libs/patchwheel/parse.go index 96e6834bc..b57aafe68 100644 --- a/libs/patchwheel/parse.go +++ b/libs/patchwheel/parse.go @@ -36,6 +36,7 @@ func calculateNewVersion(info WheelInfo, mtime time.Time) (newVersion, newFilena // ParseWheelFilename parses a wheel filename and extracts its components. // Wheel filenames follow the pattern: {distribution}-{version}(-{build tag})?-{python_tag}-{abi_tag}-{platform_tag}.whl +// https://peps.python.org/pep-0491 func ParseWheelFilename(filename string) (WheelInfo, error) { parts := strings.Split(filename, "-") if len(parts) < 5 { @@ -46,11 +47,13 @@ func ParseWheelFilename(filename string) (WheelInfo, error) { return WheelInfo{}, fmt.Errorf("invalid wheel filename format: too many parts in %s", filename) } - if !strings.HasSuffix(parts[len(parts)-1], ".whl") { + trimmedLastTag, foundWhl := strings.CutSuffix(parts[len(parts)-1], ".whl") + + if !foundWhl { return WheelInfo{}, fmt.Errorf("invalid wheel filename format: missing .whl extension in %s", filename) } - parts[len(parts)-1] = strings.TrimSuffix(parts[len(parts)-1], ".whl") + parts[len(parts)-1] = trimmedLastTag return WheelInfo{ Distribution: parts[0],