Skip to content

Commit

Permalink
fix: remove all other groups to indicate production dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Jan 7, 2025
1 parent e8da3b1 commit 86aad9d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
16 changes: 7 additions & 9 deletions pkg/lockfile/parse-poetry-lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/lockfile/parse-poetry-lock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit 86aad9d

Please sign in to comment.