Skip to content

Commit

Permalink
Fix pipenv Test
Browse files Browse the repository at this point in the history
  • Loading branch information
sarao1310 committed Aug 2, 2023
1 parent 2172525 commit 4da5aaf
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions utils/pythonutils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,41 +256,38 @@ func InstallWithLogParsing(tool PythonTool, commandArgs []string, log utils.Log,
// This regular expression allows matching any input, while the execFunc verifies whether the line contains the phrase "Using cached."
// If it does, we proceed to concatenate subsequent lines until we encounter a "(" symbol, indicating the end of the cache file path.
ExecFunc: func(pattern *gofrogcmd.CmdOutputPattern) (string, error) {
// Check for out of bound results.
if len(pattern.MatchedResults)-1 < 0 {
log.Debug(fmt.Sprintf("Failed extracting package name from line: %s", pattern.Line))
return pattern.Line, nil
}
// If this pattern matched before package-name was found, do not collect this path.
if !expectingPackageFilePath {
log.Debug(fmt.Sprintf("Could not resolve package name for download path: %s , continuing...", packageName))
return pattern.Line, nil
}
if strings.Contains(pattern.MatchedResults[0], "Using cached") {
usingCachedMode = true
}
if usingCachedMode {
// Check for out of bound results.
if len(pattern.MatchedResults)-1 < 0 {
log.Debug(fmt.Sprintf("Failed extracting package name from line: %s", pattern.Line))
return pattern.Line, nil
}
// If this pattern matched before package-name was found, do not collect this path.
if !expectingPackageFilePath {
log.Debug(fmt.Sprintf("Could not resolve package name for download path: %s , continuing...", packageName))
return pattern.Line, nil
}
cache = strings.Join([]string{cache, strings.Join(pattern.MatchedResults, "")}, "")
if strings.Contains(cache, "(") {
cache, _, _ = strings.Cut(cache, "(")
_, cache, _ = strings.Cut(cache, "Using cached")
cache = strings.ReplaceAll(cache, " ", "")
// Save dependency information.

lastSlashIndex := strings.LastIndex(cache, "/")
var fileName string
if lastSlashIndex == -1 {
fileName = cache
} else {
fileName = cache[lastSlashIndex+1:]
}

dependenciesMap[strings.ToLower(packageName)] = entities.Dependency{Id: fileName}
// Clean cache path, and expectingPackageFilePath and usingCachedMode flags
cache = ""
expectingPackageFilePath = false
usingCachedMode = false

log.Debug(fmt.Sprintf("Found package: %s installed with: %s", packageName, fileName))
return pattern.Line, nil
}
Expand Down

0 comments on commit 4da5aaf

Please sign in to comment.