Skip to content

Commit

Permalink
Fix pipenv Test
Browse files Browse the repository at this point in the history
  • Loading branch information
sarao1310 committed Jul 31, 2023
1 parent cf98bba commit 9b8e020
Showing 1 changed file with 29 additions and 31 deletions.
60 changes: 29 additions & 31 deletions utils/pythonutils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,46 +254,44 @@ func InstallWithLogParsing(tool PythonTool, commandArgs []string, log utils.Log,
return pattern.Line, nil
},
}

if tool == Pipenv {
ver, err := getPipEnvVersion(log)
ver, err := getPipEnvVersion()
if err != nil {
return nil, err
}
verifyPipEnvVersion := ver.Compare("2023.7.23") == 1 || ver.Compare("2023.7.23") == 0
if tool == Pipenv && verifyPipEnvVersion {
_, stderr, _, err := gofrogcmd.RunCmdWithOutputParser(installCmd, true)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed running %s command with error: '%s - %s'", string(tool), err.Error(), stderr)
}
if ver.Compare("2023.7.23") == 1 || ver.Compare("2023.7.23") == 0 {
_, stderr, _, err := gofrogcmd.RunCmdWithOutputParser(installCmd, true)
if err != nil {
return nil, fmt.Errorf("failed running %s command with error: '%s - %s'", string(tool), err.Error(), stderr)
stderr = strings.ReplaceAll(stderr, "\n", "")
usingCached := usingCachedRegexp.FindAllStringSubmatch(stderr, -1)
for _, current := range usingCached {
filePath := current[1]
lastSlashIndex := strings.LastIndex(filePath, "/")
var fileName string
if lastSlashIndex == -1 {
fileName = filePath
} else {
fileName = filePath[lastSlashIndex+1:]
}
stderr = strings.ReplaceAll(stderr, "\n", "")
usingCached := usingCachedRegexp.FindAllStringSubmatch(stderr, -1)
for _, current := range usingCached {
filePath := current[1]
lastSlashIndex := strings.LastIndex(filePath, "/")
var fileName string
if lastSlashIndex == -1 {
fileName = filePath
} else {
fileName = filePath[lastSlashIndex+1:]
}
dependenciesMap[strings.ToLower(packageName)] = entities.Dependency{Id: fileName}
dependenciesMap[strings.ToLower(packageName)] = entities.Dependency{Id: fileName}
_, errorOut, _, err := gofrogcmd.RunCmdWithOutputParser(installCmd, true, &dependencyNameParser, &downloadedFileParser, &installedPackagesParser)
if err != nil {
return nil, fmt.Errorf("failed running %s command with error: '%s - %s'", string(tool), err.Error(), errorOut)
}
}
}

// Execute command.
_, errorOut, _, err := gofrogcmd.RunCmdWithOutputParser(installCmd, true, &dependencyNameParser, &downloadedFileParser, &cachedFileParser, &installedPackagesParser)
if err != nil {
return nil, fmt.Errorf("failed running %s command with error: '%s - %s'", string(tool), err.Error(), errorOut)
} else {
// Execute command.
_, errorOut, _, err := gofrogcmd.RunCmdWithOutputParser(installCmd, true, &dependencyNameParser, &downloadedFileParser, &cachedFileParser, &installedPackagesParser)
if err != nil {
return nil, fmt.Errorf("failed running %s command with error: '%s - %s'", string(tool), err.Error(), errorOut)
}
}
return dependenciesMap, nil
}

// todo: think if you need to pass the log.
func getPipEnvVersion(log utils.Log) (*version.Version, error) {
if log == nil {
log = &utils.NullLog{}
}
func getPipEnvVersion() (*version.Version, error) {
versionData, err := gofrogcmd.RunCmdOutput(utils.NewCommand(string(Pipenv), "--version", []string{}))
if err != nil {
return nil, err
Expand Down

0 comments on commit 9b8e020

Please sign in to comment.