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

Commit a2850bc

Browse files
fridexdlorenc
authored andcommitted
Search for Python version also in /usr/lib/python (#157)
* 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). * Switch to a for loop.
1 parent a290a87 commit a2850bc

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

differs/pip_diff.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,21 @@ func addToMap(packages map[string]map[string]util.PackageInfo, pack string, path
123123

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

132-
for _, file := range libContents {
133-
pattern := regexp.MustCompile("^python[0-9]+\\.[0-9]+$")
134-
match := pattern.FindString(file.Name())
135-
if match != "" {
136-
matches = append(matches, match)
128+
libPaths := []string{"usr/local/lib", "usr/lib"}
129+
for _, lp := range libPaths {
130+
libPath := filepath.Join(pathToLayer, lp)
131+
libContents, err := ioutil.ReadDir(libPath)
132+
if err != nil {
133+
logrus.Debugf("Could not find %s to determine Python version", err)
134+
continue
135+
}
136+
for _, file := range libContents {
137+
match := pattern.FindString(file.Name())
138+
if match != "" {
139+
matches = append(matches, match)
140+
}
137141
}
138142
}
139143
return matches, nil

differs/pip_diff_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ func TestGetPythonVersion(t *testing.T) {
3333
{
3434
layerPath: "testDirs/pipTests/pythonVersionTests/notAFolder",
3535
expectedVersions: []string{},
36-
err: true,
36+
err: false,
3737
},
3838
{
3939
layerPath: "testDirs/pipTests/pythonVersionTests/noLibLayer",
4040
expectedVersions: []string{},
41-
err: true,
41+
err: false,
4242
},
4343
{
4444
layerPath: "testDirs/pipTests/pythonVersionTests/noPythonLayer",

0 commit comments

Comments
 (0)