diff --git a/pkg/lockfile/parse-poetry-lock.go b/pkg/lockfile/parse-poetry-lock.go index 0886b84cb3..85874f4a53 100644 --- a/pkg/lockfile/parse-poetry-lock.go +++ b/pkg/lockfile/parse-poetry-lock.go @@ -33,18 +33,16 @@ func (e PoetryLockExtractor) ShouldExtract(path string) bool { return filepath.Base(path) == "poetry.lock" } -// removeMainGroup removes the "main" group from the list of groups, -// as it is the default group used by Poetry for dependencies -func removeMainGroup(groups []string) []string { - var g []string - +func resolvePoetryPackageGroups(groups []string) []string { for _, group := range groups { - if group != "main" { - g = append(g, group) + // the "main" group is the default group used for "production" dependencies, + // which we represent by an empty slice aka no groups + if group == "main" { + return []string{} } } - return g + return groups } func (e PoetryLockExtractor) Extract(f DepFile) ([]PackageDetails, error) { @@ -63,7 +61,7 @@ func (e PoetryLockExtractor) Extract(f DepFile) ([]PackageDetails, error) { Name: lockPackage.Name, Version: lockPackage.Version, Commit: lockPackage.Source.Commit, - DepGroups: removeMainGroup(lockPackage.Groups), + DepGroups: resolvePoetryPackageGroups(lockPackage.Groups), Ecosystem: PoetryEcosystem, CompareAs: PoetryEcosystem, } diff --git a/pkg/lockfile/parse-poetry-lock_test.go b/pkg/lockfile/parse-poetry-lock_test.go index c916ac9b5a..ab373bd5c3 100644 --- a/pkg/lockfile/parse-poetry-lock_test.go +++ b/pkg/lockfile/parse-poetry-lock_test.go @@ -247,12 +247,14 @@ func TestParsePoetryLock_v2_MultiplePackages(t *testing.T) { Version: "1.22.0", Ecosystem: lockfile.PoetryEcosystem, CompareAs: lockfile.PoetryEcosystem, + DepGroups: []string{}, }, { Name: "protobuf", Version: "4.25.5", Ecosystem: lockfile.PoetryEcosystem, CompareAs: lockfile.PoetryEcosystem, + DepGroups: []string{}, }, { Name: "python-dateutil", @@ -266,7 +268,7 @@ func TestParsePoetryLock_v2_MultiplePackages(t *testing.T) { Version: "1.17.0", Ecosystem: lockfile.PoetryEcosystem, CompareAs: lockfile.PoetryEcosystem, - DepGroups: []string{"dev", "test"}, + DepGroups: []string{}, }, { Name: "typing-extensions",