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

Commit 7b527f3

Browse files
committed
Search for Python version also in /usr/lib/
Path to Python is different on deb-based distributions and rpm-based distributions (e.g. Fedora, CentOS).
1 parent 3d6d468 commit 7b527f3

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

differs/pip_diff.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package differs
1818

1919
import (
2020
"io/ioutil"
21+
"os"
2122
"path/filepath"
2223
"regexp"
2324
"strings"
@@ -123,13 +124,28 @@ func addToMap(packages map[string]map[string]util.PackageInfo, pack string, path
123124

124125
func getPythonVersion(pathToLayer string) ([]string, error) {
125126
matches := []string{}
127+
128+
// Debian based distros
126129
libPath := filepath.Join(pathToLayer, "usr/local/lib")
127130
libContents, err := ioutil.ReadDir(libPath)
128131
if err != nil {
129-
return matches, err
132+
logrus.Warnf("Could not find /usr/local/lib to determine Python version, trying /usr/lib: %s", err)
133+
libContents = []os.FileInfo{}
134+
}
135+
136+
// Fedora, CentOS, RHEL, ...
137+
libPath = filepath.Join(pathToLayer, "usr/lib")
138+
libContents2, err2 := ioutil.ReadDir(libPath)
139+
if err2 != nil {
140+
if err != nil {
141+
logrus.Errorf("Could not find /usr/lib nor /usr/local/lib to determine Python version: %s", err2)
142+
return matches, err
143+
}
144+
logrus.Warnf("Could not find /usr/lib to determine Python version, using /usr/local/lib: %s", err2)
145+
libContents2 = []os.FileInfo{}
130146
}
131147

132-
for _, file := range libContents {
148+
for _, file := range append(libContents, libContents2...) {
133149
pattern := regexp.MustCompile("^python[0-9]+\\.[0-9]+$")
134150
match := pattern.FindString(file.Name())
135151
if match != "" {

0 commit comments

Comments
 (0)