Skip to content

Commit 5b28595

Browse files
committed
Add pipenv dependencies
1 parent 2b5ca25 commit 5b28595

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

deps/python_fetcher.go

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (gdf PythonDepsFetcher) GetDepsList(ctx context.Context, restyClient *resty
4141
re := regexp.MustCompile(`^([a-zA-Z0-9_-]+)[^a-zA-Z0-9_-]`)
4242
match := re.FindStringSubmatch(line)
4343
if len(match) >= 2 {
44-
directDeps = append(directDeps, match[1])
44+
directDeps = append(directDeps, strings.ToLower(match[1]))
4545
}
4646
}
4747
}
@@ -63,7 +63,7 @@ func (gdf PythonDepsFetcher) GetDepsList(ctx context.Context, restyClient *resty
6363

6464
if depSection, ok := cfg.Get("tool.poetry.dependencies").(*toml.Tree); ok {
6565
for name := range depSection.ToMap() {
66-
directDeps = append(directDeps, name)
66+
directDeps = append(directDeps, strings.ToLower(name))
6767
}
6868
}
6969
}
@@ -94,6 +94,40 @@ func (gdf PythonDepsFetcher) GetDepsList(ctx context.Context, restyClient *resty
9494
}
9595
}
9696

97+
pipfileUrl := fmt.Sprintf("%s/%s/%s/Pipfile", rawGHUrl, ghRepo, result.DefaultBranch)
98+
99+
resp, err = restyReq.Get(pipfileUrl)
100+
101+
if resp.IsSuccess() && err == nil {
102+
reader := bytes.NewReader([]byte(resp.Body()))
103+
scanner := bufio.NewScanner(reader)
104+
105+
dependencyRegex := regexp.MustCompile(`\b([\w\d_-]+)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s]+))`)
106+
currentSection := ""
107+
108+
for scanner.Scan() {
109+
line := strings.TrimSpace(scanner.Text())
110+
111+
// Check if the line contains a section header
112+
if strings.HasPrefix(line, "[") && strings.HasSuffix(line, "]") {
113+
currentSection = line[1 : len(line)-1]
114+
continue
115+
}
116+
117+
// Check if the line contains a dependency
118+
matches := dependencyRegex.FindStringSubmatch(line)
119+
if len(matches) >= 2 && (currentSection == "dev-packages" || currentSection == "packages") {
120+
dependencyName := matches[1]
121+
directDeps = append(directDeps, strings.ToLower(dependencyName))
122+
}
123+
}
124+
125+
// Check for errors during scanning
126+
if err := scanner.Err(); err != nil {
127+
return err
128+
}
129+
}
130+
97131
result.DirectDeps = directDeps
98132

99133
return nil

main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,23 @@ func main() {
114114
result, _ = clientGQL.GetAllStats(ctx, "gen2brain/malgo")
115115
fmt.Println(result)
116116

117+
// package.json
117118
result, _ = clientGQL.GetAllStats(ctx, "winstonjs/winston")
118119
fmt.Println(result)
119120

121+
// requirements.txt
120122
result, _ = clientGQL.GetAllStats(ctx, "encode/uvicorn")
121123
fmt.Println(result)
122124

125+
// poetry pyproject.toml
123126
result, _ = clientGQL.GetAllStats(ctx, "copier-org/copier")
124127
fmt.Println(result)
125128

129+
// setup.py
126130
result, _ = clientGQL.GetAllStats(ctx, "httpie/cli")
127131
fmt.Println(result)
132+
133+
// pipenv Pipfile
134+
result, _ = clientGQL.GetAllStats(ctx, "zappa/Zappa")
135+
fmt.Println(result)
128136
}

0 commit comments

Comments
 (0)