Skip to content

Commit 3e61f54

Browse files
committed
Support pipenv
1 parent edcac34 commit 3e61f54

File tree

5 files changed

+148
-3
lines changed

5 files changed

+148
-3
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ However, some libraries have archived their source code repositories or have had
1717
| JavaScript | yarn | yarn.lock | :heavy_check_mark: |
1818
| PHP | composer | composer.lock | :heavy_check_mark: |
1919
| Python | pip | requirements.txt | :heavy_check_mark: |
20-
| Python | pipenv | Pipfile.lock | (later) |
20+
| Python | pipenv | Pipfile.lock | :heavy_check_mark: |
2121
| Python | poetry | poetry.lock | (later) |
2222
| Ruby | bundler | Gemfile.lock | :heavy_check_mark: |
2323
| Rust | cargo | Cargo.lock | :heavy_check_mark: |

cmd/diagnose.go

+1
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ var doctors = Doctors{
215215
"bundler": ruby.NewBundlerDoctor(),
216216
"yarn": nodejs.NewYarnDoctor(),
217217
"pip": python.NewPipDoctor(),
218+
"pipenv": python.NewPipenvDoctor(),
218219
"npm": nodejs.NewNPMDoctor(),
219220
"composer": php.NewComposerDoctor(),
220221
"golang": golang.NewGolangDoctor(),

cmd/python/pipenv.go

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package python
2+
3+
import (
4+
"net/http"
5+
6+
parser_io "github.com/aquasecurity/go-dep-parser/pkg/io"
7+
"github.com/aquasecurity/go-dep-parser/pkg/python/pipenv"
8+
"github.com/aquasecurity/go-dep-parser/pkg/types"
9+
)
10+
11+
type PipenvDoctor struct {
12+
HTTPClient http.Client
13+
}
14+
15+
func NewPipenvDoctor() *PipenvDoctor {
16+
client := &http.Client{}
17+
return &PipenvDoctor{HTTPClient: *client}
18+
}
19+
20+
func (d *PipenvDoctor) Libraries(r parser_io.ReadSeekerAt) []types.Library {
21+
p := pipenv.NewParser()
22+
libs, _, _ := p.Parse(r)
23+
return libs
24+
}
25+
26+
func (d *PipenvDoctor) SourceCodeURL(lib types.Library) (string, error) {
27+
pypi := Pypi{name: lib.Name}
28+
url, err := pypi.fetchURLFromRegistry(d.HTTPClient)
29+
return url, err
30+
}

cmd/python/pipenv/testdata/Pipfile.lock

+104
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/python/pypi.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ const PYPI_REGISTRY_API = "https://pypi.org/pypi/%s/json"
1414
type PypiRegistryResponse struct {
1515
Info struct {
1616
ProjectUrls struct {
17-
SourceCode string `json:"Source Code"`
18-
Source string `json:"Source"`
17+
SourceCode string `json:"Source Code"`
18+
Source string `json:"Source"`
19+
Code string `json:"Code"`
20+
GitHubProject string `json:"GitHub Project"`
1921
} `json:"project_urls"`
2022
} `json:"info"`
2123
}
@@ -54,5 +56,13 @@ func (p *Pypi) fetchURLFromRegistry(client http.Client) (string, error) {
5456
return PypiRegistryResponse.Info.ProjectUrls.SourceCode, nil
5557
}
5658

59+
if PypiRegistryResponse.Info.ProjectUrls.Code != "" {
60+
return PypiRegistryResponse.Info.ProjectUrls.Code, nil
61+
}
62+
63+
if PypiRegistryResponse.Info.ProjectUrls.GitHubProject != "" {
64+
return PypiRegistryResponse.Info.ProjectUrls.GitHubProject, nil
65+
}
66+
5767
return PypiRegistryResponse.Info.ProjectUrls.Source, nil
5868
}

0 commit comments

Comments
 (0)