Skip to content
This repository was archived by the owner on Mar 27, 2024. It is now read-only.

Commit 84c27d4

Browse files
authored
Merge pull request #109 from nkubala/python_packages
add default python package directories, and support egg modules
2 parents 45056ce + 9bbdad7 commit 84c27d4

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

differs/pip_diff.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,14 @@ func (a PipAnalyzer) getPackages(image pkgutil.Image) (map[string]map[string]uti
6161
return packages, nil
6262
}
6363

64+
// default python package installation directories in unix
65+
// these are hardcoded in the python source; unfortunately no way to retrieve them from env
6466
for _, pythonVersion := range pythonVersions {
65-
packagesPath := filepath.Join(path, "usr/local/lib", pythonVersion, "site-packages")
66-
pythonPaths = append(pythonPaths, packagesPath)
67+
pythonPaths = append(pythonPaths, filepath.Join(path, "usr/lib", pythonVersion))
68+
pythonPaths = append(pythonPaths, filepath.Join(path, "usr/lib", pythonVersion, "dist-packages"))
69+
pythonPaths = append(pythonPaths, filepath.Join(path, "usr/lib", pythonVersion, "site-packages"))
70+
pythonPaths = append(pythonPaths, filepath.Join(path, "usr/local/lib", pythonVersion, "dist-packages"))
71+
pythonPaths = append(pythonPaths, filepath.Join(path, "usr/local/lib", pythonVersion, "site-packages"))
6772
}
6873

6974
for _, pythonPath := range pythonPaths {
@@ -77,7 +82,7 @@ func (a PipAnalyzer) getPackages(image pkgutil.Image) (map[string]map[string]uti
7782
c := contents[i]
7883
fileName := c.Name()
7984
// check if package
80-
packageDir := regexp.MustCompile("^([a-z|A-Z|0-9|_]+)-(([0-9]+?\\.){2,3})dist-info$")
85+
packageDir := regexp.MustCompile("^([a-z|A-Z|0-9|_]+)-(([0-9]+?\\.){2,3})(dist-info|egg-info)$")
8186
packageMatch := packageDir.FindStringSubmatch(fileName)
8287
if len(packageMatch) != 0 {
8388
packageName := packageMatch[1]
@@ -91,7 +96,6 @@ func (a PipAnalyzer) getPackages(image pkgutil.Image) (map[string]map[string]uti
9196
size = pkgutil.GetSize(packagePath)
9297
} else if i+1 < len(contents) && contents[i+1].Name() == packageName+".py" {
9398
size = contents[i+1].Size()
94-
9599
} else {
96100
glog.Errorf("Could not find Python package %s for corresponding metadata info", packageName)
97101
continue

0 commit comments

Comments
 (0)