diff --git a/utils/pythonutils/utils.go b/utils/pythonutils/utils.go index d21a406d..bffc35a2 100644 --- a/utils/pythonutils/utils.go +++ b/utils/pythonutils/utils.go @@ -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