@@ -18,6 +18,7 @@ package differs
18
18
19
19
import (
20
20
"io/ioutil"
21
+ "os"
21
22
"path/filepath"
22
23
"regexp"
23
24
"strings"
@@ -123,13 +124,28 @@ func addToMap(packages map[string]map[string]util.PackageInfo, pack string, path
123
124
124
125
func getPythonVersion (pathToLayer string ) ([]string , error ) {
125
126
matches := []string {}
127
+
128
+ // Debian based distros
126
129
libPath := filepath .Join (pathToLayer , "usr/local/lib" )
127
130
libContents , err := ioutil .ReadDir (libPath )
128
131
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 {}
130
146
}
131
147
132
- for _ , file := range libContents {
148
+ for _ , file := range append ( libContents , libContents2 ... ) {
133
149
pattern := regexp .MustCompile ("^python[0-9]+\\ .[0-9]+$" )
134
150
match := pattern .FindString (file .Name ())
135
151
if match != "" {
0 commit comments