-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(python): skip dev group's deps for poetry (#8106)
Signed-off-by: nikpivkin <nikita.pivkin@smartforce.io>
- Loading branch information
Showing
11 changed files
with
650 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package python | ||
|
||
import "strings" | ||
|
||
// NormalizePkgName normalizes the package name based on pep-0426 | ||
func NormalizePkgName(name string) string { | ||
// The package names don't use `_`, `.` or upper case, but dependency names can contain them. | ||
// We need to normalize those names. | ||
// cf. https://peps.python.org/pep-0426/#name | ||
name = strings.ToLower(name) // e.g. https://github.com/python-poetry/poetry/blob/c8945eb110aeda611cc6721565d7ad0c657d453a/poetry.lock#L819 | ||
name = strings.ReplaceAll(name, "_", "-") // e.g. https://github.com/python-poetry/poetry/blob/c8945eb110aeda611cc6721565d7ad0c657d453a/poetry.lock#L50 | ||
name = strings.ReplaceAll(name, ".", "-") // e.g. https://github.com/python-poetry/poetry/blob/c8945eb110aeda611cc6721565d7ad0c657d453a/poetry.lock#L816 | ||
return name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package python_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/aquasecurity/trivy/pkg/dependency/parser/python" | ||
) | ||
|
||
func Test_NormalizePkgName(t *testing.T) { | ||
tests := []struct { | ||
pkgName string | ||
expected string | ||
}{ | ||
{ | ||
pkgName: "SecretStorage", | ||
expected: "secretstorage", | ||
}, | ||
{ | ||
pkgName: "pywin32-ctypes", | ||
expected: "pywin32-ctypes", | ||
}, | ||
{ | ||
pkgName: "jaraco.classes", | ||
expected: "jaraco-classes", | ||
}, | ||
{ | ||
pkgName: "green_gdk", | ||
expected: "green-gdk", | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.pkgName, func(t *testing.T) { | ||
assert.Equal(t, tt.expected, python.NormalizePkgName(tt.pkgName)) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.