Skip to content

Commit 8e65997

Browse files
committed
feat: replace poetry.lock parser
1 parent 8d3d1c2 commit 8e65997

File tree

1 file changed

+2
-47
lines changed

1 file changed

+2
-47
lines changed

pkg/lockfile/parse-poetry-lock.go

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,11 @@
11
package lockfile
22

33
import (
4-
"fmt"
5-
"os"
6-
7-
"github.com/BurntSushi/toml"
4+
"github.com/google/osv-scalibr/extractor/filesystem/language/python/poetrylock"
85
)
96

10-
type PoetryLockPackageSource struct {
11-
Type string `toml:"type"`
12-
Commit string `toml:"resolved_reference"`
13-
}
14-
15-
type PoetryLockPackage struct {
16-
Name string `toml:"name"`
17-
Version string `toml:"version"`
18-
Source PoetryLockPackageSource `toml:"source"`
19-
}
20-
21-
type PoetryLockFile struct {
22-
Version int `toml:"version"`
23-
Packages []PoetryLockPackage `toml:"package"`
24-
}
25-
267
const PoetryEcosystem = PipEcosystem
278

289
func ParsePoetryLock(pathToLockfile string) ([]PackageDetails, error) {
29-
var parsedLockfile *PoetryLockFile
30-
31-
lockfileContents, err := os.ReadFile(pathToLockfile)
32-
33-
if err != nil {
34-
return []PackageDetails{}, fmt.Errorf("could not read %s: %w", pathToLockfile, err)
35-
}
36-
37-
err = toml.Unmarshal(lockfileContents, &parsedLockfile)
38-
39-
if err != nil {
40-
return []PackageDetails{}, fmt.Errorf("could not parse %s: %w", pathToLockfile, err)
41-
}
42-
43-
packages := make([]PackageDetails, 0, len(parsedLockfile.Packages))
44-
45-
for _, lockPackage := range parsedLockfile.Packages {
46-
packages = append(packages, PackageDetails{
47-
Name: lockPackage.Name,
48-
Version: lockPackage.Version,
49-
Commit: lockPackage.Source.Commit,
50-
Ecosystem: PoetryEcosystem,
51-
CompareAs: PoetryEcosystem,
52-
})
53-
}
54-
55-
return packages, nil
10+
return extract(pathToLockfile, poetrylock.New(), PoetryEcosystem)
5611
}

0 commit comments

Comments
 (0)