-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(python): skip dev group's deps for poetry #8106
Open
nikpivkin
wants to merge
7
commits into
aquasecurity:main
Choose a base branch
from
nikpivkin:poetry-dev-deps
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
23d4942
fix(python): skip dev group's deps for poetry
nikpivkin a515a32
use set for poetry dependencies
nikpivkin e2eb795
move NormalizePkgName to common package
nikpivkin 7de61c8
use package id for resolve dependency tree
nikpivkin 43adf6c
refactor: rename getProdDeps -> filterProdPackages
nikpivkin a45fc4d
refactor: remove unnecessary package checking
nikpivkin d1e2450
refactor: use xerrors instead of fmt
nikpivkin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,9 @@ package poetry | |
import ftypes "github.com/aquasecurity/trivy/pkg/fanal/types" | ||
|
||
var ( | ||
// docker run --name pipenv --rm -it python@sha256:e1141f10176d74d1a0e87a7c0a0a5a98dd98ec5ac12ce867768f40c6feae2fd9 sh | ||
// docker run --name poetry --rm -it python@sha256:e1141f10176d74d1a0e87a7c0a0a5a98dd98ec5ac12ce867768f40c6feae2fd9 sh | ||
// apk add curl | ||
// curl -sSL https://install.python-poetry.org | python3 - | ||
// curl -sSL https://install.python-poetry.org | POETRY_VERSION=1.1.7 python3 - | ||
// export PATH=/root/.local/bin:$PATH | ||
// poetry new normal && cd normal | ||
// poetry add [email protected] | ||
|
@@ -14,9 +14,9 @@ var ( | |
{ID: "[email protected]", Name: "pypi", Version: "2.1"}, | ||
} | ||
|
||
// docker run --name pipenv --rm -it python@sha256:e1141f10176d74d1a0e87a7c0a0a5a98dd98ec5ac12ce867768f40c6feae2fd9 sh | ||
// docker run --name poetry --rm -it python@sha256:e1141f10176d74d1a0e87a7c0a0a5a98dd98ec5ac12ce867768f40c6feae2fd9 sh | ||
// apk add curl | ||
// curl -sSL https://install.python-poetry.org | python3 - | ||
// curl -sSL https://install.python-poetry.org | POETRY_VERSION=1.1.7 python3 - | ||
// export PATH=/root/.local/bin:$PATH | ||
// poetry new many && cd many | ||
// curl -o poetry.lock https://raw.githubusercontent.com/python-poetry/poetry/c8945eb110aeda611cc6721565d7ad0c657d453a/poetry.lock | ||
|
@@ -108,9 +108,9 @@ var ( | |
{ID: "[email protected]", DependsOn: []string{"[email protected]"}}, | ||
} | ||
|
||
// docker run --name pipenv --rm -it python@sha256:e1141f10176d74d1a0e87a7c0a0a5a98dd98ec5ac12ce867768f40c6feae2fd9 sh | ||
// docker run --name poetry --rm -it python@sha256:e1141f10176d74d1a0e87a7c0a0a5a98dd98ec5ac12ce867768f40c6feae2fd9 sh | ||
// apk add curl | ||
// curl -sSL https://install.python-poetry.org | python3 - | ||
// curl -sSL https://install.python-poetry.org | POETRY_VERSION=1.1.7 python3 - | ||
// export PATH=/root/.local/bin:$PATH | ||
// poetry new web && cd web | ||
// poetry add [email protected] | ||
|
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: for consistency and stacktrace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed d1e2450