Skip to content

Commit 7cb0b45

Browse files
authored
Fix patchwheel.ParseWheelFilename to extract basename (#2521)
## Why This is a minor change but makes it easier to use, no need to remember doing this on the caller side. Relying on this in #2520 Follow up to #2427 ## Tests New unit tests.
1 parent fc9544e commit 7cb0b45

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

libs/patchwheel/parse.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package patchwheel
22

33
import (
44
"fmt"
5+
"path/filepath"
56
"strconv"
67
"strings"
78
"time"
@@ -39,6 +40,7 @@ func calculateNewVersion(info WheelInfo, mtime time.Time) (newVersion, newFilena
3940
// The function does not try hard to validate if the format is correct, it tries to parse whatever is available.
4041
// However, it does require 5 or 6 components in the filename.
4142
func ParseWheelFilename(filename string) (WheelInfo, error) {
43+
filename = filepath.Base(filename)
4244
parts := strings.Split(filename, "-")
4345
if len(parts) < 5 {
4446
return WheelInfo{}, fmt.Errorf("invalid wheel filename format: not enough parts in %s", filename)

libs/patchwheel/parse_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ func TestParseWheelFilename(t *testing.T) {
7878
wantTags: []string{"py3", "none", "any"},
7979
wantErr: false,
8080
},
81+
{
82+
filename: "./myproj-0.1.0-py3-none-any.whl",
83+
wantDistribution: "myproj",
84+
wantVersion: "0.1.0",
85+
wantTags: []string{"py3", "none", "any"},
86+
wantErr: false,
87+
},
8188
{
8289
filename: "myproj-0.1.0+20240303123456-py3-none-any.whl",
8390
wantDistribution: "myproj",
@@ -92,6 +99,13 @@ func TestParseWheelFilename(t *testing.T) {
9299
wantTags: []string{"py3", "none", "any"},
93100
wantErr: false,
94101
},
102+
{
103+
filename: "subdir/myproj-0.1.0+20240303123456-py3-none-any.whl",
104+
wantDistribution: "myproj",
105+
wantVersion: "0.1.0+20240303123456",
106+
wantTags: []string{"py3", "none", "any"},
107+
wantErr: false,
108+
},
95109
// Test cases adapted from wheelodex/wheel-filename
96110
// https://github.com/wheelodex/wheel-filename/blob/f5a72b560d016cc9663c8b5a094c96dc338a2209/test/test_parse.py
97111
// MIT License: https://github.com/wheelodex/wheel-filename/blob/f5a72b560d016cc9663c8b5a094c96dc338a2209/LICENSE

0 commit comments

Comments
 (0)