/
pipenvutils.go
29 lines (26 loc) · 984 Bytes
/
pipenvutils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package pythonutils
import (
"encoding/json"
"github.com/jfrog/gofrog/io"
)
// Executes pipenv graph.
// Returns a dependency map of all the installed pipenv packages in the current environment and also another list of the top level dependencies
// 'dependenciesGraph' - map between all parent modules and their child dependencies
// 'topLevelPackagesList' - list of all top level dependencies ( root dependencies only)
func getPipenvDependencies(srcPath string) (dependenciesGraph map[string][]string, topLevelDependencies []string, err error) {
// Run pipenv graph
pipenvGraphCmd := io.NewCommand("pipenv", "graph", []string{"--json"})
pipenvGraphCmd.Dir = srcPath
output, err := pipenvGraphCmd.RunWithOutput()
if err != nil {
return
}
// Parse into array.
packages := make([]pythonDependencyPackage, 0)
err = json.Unmarshal(output, &packages)
if err != nil {
return
}
dependenciesGraph, topLevelDependencies, err = parseDependenciesToGraph(packages)
return
}