Skip to content

Commit 09d5952

Browse files
authored
internal: Fixes for IsLocalPathInPipFlag and IsLibraryLocal (#3716)
## Changes Added ^\s* for pip flag regexp so we don't match `foo-bar` as a flag Renamed variable to avoid shadowing ## Why Followups for #3708
1 parent 4246149 commit 09d5952

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

bundle/libraries/local_path.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ var PipFlagsWithLocalPaths = []string{
8181

8282
func IsLocalPathInPipFlag(dep string) (string, string, bool) {
8383
for _, flag := range PipFlagsWithLocalPaths {
84-
dep, ok := strings.CutPrefix(dep, flag+" ")
84+
depWithoutFlag, ok := strings.CutPrefix(dep, flag+" ")
8585
if ok {
86-
dep = strings.TrimSpace(dep)
87-
return dep, flag, IsLocalPath(dep)
86+
depWithoutFlag = strings.TrimSpace(depWithoutFlag)
87+
return depWithoutFlag, flag, IsLocalPath(depWithoutFlag)
8888
}
8989
}
9090

@@ -95,7 +95,7 @@ func containsPipFlag(input string) bool {
9595
// Trailing space means the the flag takes an argument or there's multiple arguments in input
9696
// Alternatively it could be a flag with no argument and no space after it
9797
// For example: -r myfile.txt or --index-url http://myindexurl.com or -i
98-
re := regexp.MustCompile(`--?[a-zA-Z0-9-]+(\s|$)`)
98+
re := regexp.MustCompile(`(^|\s+)--?[a-zA-Z0-9-]+(\s+|$)`)
9999
return re.MatchString(input)
100100
}
101101

bundle/libraries/local_path_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,11 @@ func TestIsLibraryLocal(t *testing.T) {
4848
{path: "../../local/*.whl", expected: true},
4949
{path: "..\\..\\local\\*.whl", expected: true},
5050
{path: "file://path/to/package/whl.whl", expected: true},
51+
{path: "local/foo-bar.whl", expected: true},
52+
5153
{path: "", expected: false},
5254
{path: "pypipackage", expected: false},
55+
{path: "foo-bar", expected: false},
5356
{path: "/Volumes/catalog/schema/volume/path.whl", expected: false},
5457
{path: "/Workspace/my_project/dist.whl", expected: false},
5558
{path: "-r ../requirements.txt", expected: false},

0 commit comments

Comments
 (0)