Skip to content

Commit

Permalink
🐛 Return empty python packages if dir does not exist.
Browse files Browse the repository at this point in the history
Signed-off-by: Preslav <[email protected]>
  • Loading branch information
preslavgerchev committed Jan 29, 2025
1 parent b3c787a commit 55bbe7b
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions providers/os/resources/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,20 @@ import (
"go.mondoo.com/cnquery/v11/types"
)

var (
defaultPythonPaths = []string{
// Linux
"/usr/local/lib/python*",
"/usr/local/lib64/python*",
"/usr/lib/python*",
"/usr/lib64/python*",
// Windows
"C:\\Python*\\Lib",
// macOS
"/opt/homebrew/lib/python*",
"/System/Library/Frameworks/Python.framework/Versions/*/lib/python*",
// we use 3.x to exclude the macOS 'Current' symlink
"/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.*/lib/python*",
}
)
var defaultPythonPaths = []string{
// Linux
"/usr/local/lib/python*",
"/usr/local/lib64/python*",
"/usr/lib/python*",
"/usr/lib64/python*",
// Windows
"C:\\Python*\\Lib",
// macOS
"/opt/homebrew/lib/python*",
"/System/Library/Frameworks/Python.framework/Versions/*/lib/python*",
// we use 3.x to exclude the macOS 'Current' symlink
"/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.*/lib/python*",
}

func initPython(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) {
if x, ok := args["path"]; ok {
Expand Down Expand Up @@ -210,8 +208,9 @@ func collectPythonPackages(runtime *plugin.Runtime, fs afero.Fs, path string) ([

fileList, err := afs.ReadDir(path)
if err != nil {
if !os.IsNotExist(err) {
if os.IsNotExist(err) {
log.Warn().Err(err).Str("dir", path).Msg("unable to open directory")
return []python.PackageDetails{}, nil
}
return nil, err
}
Expand Down

0 comments on commit 55bbe7b

Please sign in to comment.