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

Search for Python version also in /usr/lib/python #157

Merged
merged 3 commits into from
Dec 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions differs/pip_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,21 @@ func addToMap(packages map[string]map[string]util.PackageInfo, pack string, path

func getPythonVersion(pathToLayer string) ([]string, error) {
matches := []string{}
libPath := filepath.Join(pathToLayer, "usr/local/lib")
libContents, err := ioutil.ReadDir(libPath)
if err != nil {
return matches, err
}
pattern := regexp.MustCompile("^python[0-9]+\\.[0-9]+$")

for _, file := range libContents {
pattern := regexp.MustCompile("^python[0-9]+\\.[0-9]+$")
match := pattern.FindString(file.Name())
if match != "" {
matches = append(matches, match)
libPaths := []string{"usr/local/lib", "usr/lib"}
for _, lp := range libPaths {
libPath := filepath.Join(pathToLayer, lp)
libContents, err := ioutil.ReadDir(libPath)
if err != nil {
logrus.Debugf("Could not find %s to determine Python version", err)
continue
}
for _, file := range libContents {
match := pattern.FindString(file.Name())
if match != "" {
matches = append(matches, match)
}
}
}
return matches, nil
Expand Down
4 changes: 2 additions & 2 deletions differs/pip_diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ func TestGetPythonVersion(t *testing.T) {
{
layerPath: "testDirs/pipTests/pythonVersionTests/notAFolder",
expectedVersions: []string{},
err: true,
err: false,
},
{
layerPath: "testDirs/pipTests/pythonVersionTests/noLibLayer",
expectedVersions: []string{},
err: true,
err: false,
},
{
layerPath: "testDirs/pipTests/pythonVersionTests/noPythonLayer",
Expand Down